|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (C) 2014 OTA Update Center |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +API_URL="https://otaupdatecenter.pro/api/v1" |
| 17 | +SC_VER="0.9.0" |
| 18 | + |
| 19 | +help=0 |
| 20 | +if [[ $# == 0 ]] ; then |
| 21 | + help=1 |
| 22 | +fi |
| 23 | + |
| 24 | +opttmp=`getopt -o hu:t:f:v:d:z:m:c:x:l:k: --long \ |
| 25 | +help,user:,type:file_id:,version:,otadate:,\ |
| 26 | +file:,md5:,changelog:,changelogfile:,\ |
| 27 | +device:,url:,key:verbose -- "$@"` |
| 28 | + |
| 29 | +if [[ $? != 0 ]] ; then echo "INPUT ERROR! Terminating" >&2 ; exit 1 ; fi |
| 30 | + |
| 31 | +eval set -- "$opttmp" |
| 32 | + |
| 33 | +USER=-1 |
| 34 | +TYPE=-1 |
| 35 | +FILE_ID=-1 |
| 36 | +VERSION=-1 |
| 37 | +OTADATE=-1 |
| 38 | +file=-1 |
| 39 | +MD5=-1 |
| 40 | +CHANGELOG=-1 |
| 41 | +changelog_file=-1 |
| 42 | +verbose=0 |
| 43 | +URL=-1 |
| 44 | +KEY="$HOME/.ssh/id_rsa" |
| 45 | + |
| 46 | +while true; do |
| 47 | + case "$1" in |
| 48 | + -u | --user ) USER="$2"; shift 2 ;; |
| 49 | + -t | --type ) TYPE="$2"; shift 2 ;; |
| 50 | + -f | --file_id ) FILE_ID="$2"; shift 2 ;; |
| 51 | + -v | --version ) VERSION="$2"; shift 2 ;; |
| 52 | + -d | --otadate ) OTADATE="$2"; shift 2 ;; |
| 53 | + -z | --file ) file="$2"; shift 2 ;; |
| 54 | + -m | --md5 ) MD5="$2"; shift 2 ;; |
| 55 | + -c | --changelog ) CHANGELOG="$2"; shift 2 ;; |
| 56 | + -x | --changelogfile ) changelog_file="$2"; shift 2 ;; |
| 57 | + -l | --url ) URL="$2"; shift 2 ;; |
| 58 | + -k | --key ) KEY="$2"; shift 2 ;; |
| 59 | + --verbose ) verbose=1; shift ;; |
| 60 | + |
| 61 | + -h | --help ) help=1; shift ; break ;; |
| 62 | + |
| 63 | + -- ) shift; break ;; |
| 64 | + * ) break ;; |
| 65 | + esac |
| 66 | +done |
| 67 | + |
| 68 | +if [[ $help == 1 ]] ; then |
| 69 | + echo |
| 70 | + echo "+=================================================================+" |
| 71 | + echo "| *** OTA Update Center - Auto Update Script HELP *** |" |
| 72 | + echo "+=================================================================+" |
| 73 | + echo "| Usage: update_rominfo.sh [-h|--help] - Print this |" |
| 74 | + echo "| update_rominfo.sh {-u|--user} <username> |" |
| 75 | + echo "| {-t|--type} {rom|kernel} |" |
| 76 | + echo "| {-f|--file_id} <file id> |" |
| 77 | + echo "| {-l|--url} <download URL> |" |
| 78 | + echo "| {-z <update.zip file>|-m <md5>} |" |
| 79 | + echo "| [{-t|--otadate} <ota date/time>] |" |
| 80 | + echo "| [{-v|--version} <ota version>] |" |
| 81 | + echo "| [{-c <changelog>|-x <changelogfile>}] |" |
| 82 | + echo "| [{-k|--key} <key file>] |" |
| 83 | + echo "| [--verbose] |" |
| 84 | + echo "+-----------------------------------------------------------------+" |
| 85 | + echo "| <user> - your username or email |" |
| 86 | + echo "| <file id> - File ID of the ROM or Kernel File to update |" |
| 87 | + echo "| found on edit page for that file on the site |" |
| 88 | + echo "| <download URL> - URL where the update.zip is hosted |" |
| 89 | + echo "| <.zip file> - update.zip file to use for getting MD5-sum |" |
| 90 | + echo "| <md5> - specify MD5 instead of calculating |" |
| 91 | + echo "| <ota date/time> - date/time of update, yyyymmdd-hhmm format |" |
| 92 | + echo "| if unspecified, current date/time is used |" |
| 93 | + echo "| <ota version> - version of ota update |" |
| 94 | + echo "| if unspecified, current version is used |" |
| 95 | + echo "| <changelog> - changelog for update (be sure to quote) |" |
| 96 | + echo "| <changelog file>- file to read changelog from |" |
| 97 | + echo "| if unspecified, blank changelog is used if |" |
| 98 | + echo "| updating version, current changelog otherwise |" |
| 99 | + echo "| <key file> - private key file to use |" |
| 100 | + echo "| if unspecified, ~/.ssh/id_rsa is used |" |
| 101 | + echo "+=================================================================+" |
| 102 | + exit 0 |
| 103 | +fi |
| 104 | + |
| 105 | +if [[ $USER_ID == -1 ]] ; then |
| 106 | + echo "User ID not specified! Terminating" >&2 |
| 107 | + exit 2 |
| 108 | +fi |
| 109 | + |
| 110 | +if [[ "$TYPE" != "rom" && "$TYPE" != "kernel" ]] ; then |
| 111 | + if [[ $TYPE == -1 ]] ; then |
| 112 | + echo "Type not specified! Terminating" >&2 |
| 113 | + else |
| 114 | + echo "Invalid type specified! Terminating" >&2 |
| 115 | + fi |
| 116 | + exit 3 |
| 117 | +fi |
| 118 | + |
| 119 | +if [[ $FILE_ID == -1 ]] ; then |
| 120 | + echo "ROM File ID not specified! Terminating" >&2 |
| 121 | + exit 4 |
| 122 | +fi |
| 123 | + |
| 124 | +if [[ $URL == -1 ]] ; then |
| 125 | + echo "Download URL not specified! Terminating" >&2 |
| 126 | + exit 5 |
| 127 | +fi |
| 128 | + |
| 129 | +if [[ $file == -1 && $MD5 == -1 ]] ; then |
| 130 | + echo "Neither file path nor file md5 specified! Terminating" >&2 |
| 131 | + exit 6 |
| 132 | +elif [[ $file != -1 && $MD5 != -1 && $verbose == 1 ]]; then |
| 133 | + echo "WARNING: both file and MD5 specified, computed MD5 will be used" |
| 134 | +fi |
| 135 | + |
| 136 | +if [[ $file != -1 ]] ; then |
| 137 | + echo -n "Computing MD5 ... " |
| 138 | + MD5=`md5sum "$file" | awk '{ print $1 }'` |
| 139 | + echo "DONE: $MD5" |
| 140 | +fi |
| 141 | + |
| 142 | +if [[ $VERSION == -1 ]] ; then |
| 143 | + VERSION="" |
| 144 | + if [[ $verbose == 1 ]] ; then |
| 145 | + echo "WARNING: version not specified, will not update version!" |
| 146 | + fi |
| 147 | +fi |
| 148 | + |
| 149 | +if [[ $OTADATE == -1 ]] ; then |
| 150 | + OTADATE=`date +%Y%m%d-%k%M` |
| 151 | + if [[ $verbose == 1 ]] ; then |
| 152 | + echo "WARNING: ota time not specified, using $OTADATE" |
| 153 | + fi |
| 154 | +fi |
| 155 | + |
| 156 | +if [[ $CHANGELOG == -1 && $changelog_file == -1 ]] ; then |
| 157 | + CHANGELOG="" |
| 158 | + if [[ $verbose == 1 ]] ; then |
| 159 | + echo "WARNING: changelog not specified, using blank changelog" |
| 160 | + fi |
| 161 | +elif [[ $CHANGELOG != -1 && $changelog_file != -1 ]] ; then |
| 162 | + echo "WARNING: both changelog text and file specified, file will be used" |
| 163 | +fi |
| 164 | + |
| 165 | +if [[ $changelog_file != -1 ]] ; then |
| 166 | + CHANGELOG=`cat "$changelog_file"` |
| 167 | +fi |
| 168 | + |
| 169 | +VERSION=`echo -n "$VERSION" | tr '"' '\"'` |
| 170 | +URL=`echo -n "$URL" | tr '"' '\"'` |
| 171 | +CHANGELOG=`echo -n "$CHANGELOG" | tr '"' '\"'` |
| 172 | + |
| 173 | +payload="{ |
| 174 | + \"version\": \"$VERSION\", |
| 175 | + \"date\": \"$OTADATE\", |
| 176 | + \"url\": \"$URL\", |
| 177 | + \"md5\": \"$MD5\", |
| 178 | + \"changelog\": \"$CHANGELOG\" |
| 179 | +}" |
| 180 | +#payload='asdftest' |
| 181 | + |
| 182 | +sig=`echo -n "$payload" | \ |
| 183 | + openssl dgst -sha1 -sign "$KEY" | \ |
| 184 | + openssl enc -base64 | \ |
| 185 | + tr -d '\n'` |
| 186 | + |
| 187 | +curl -v \ |
| 188 | + -X POST \ |
| 189 | + --data "$payload" \ |
| 190 | + -H "Content-Type: application/json" \ |
| 191 | + -H "X-API-Username: $USER" \ |
| 192 | + -H "X-API-Signature: $sig" \ |
| 193 | + -A "OTA Update Center Upload Script v$SC_VER" \ |
| 194 | + "$API_URL/${TYPE}s/files/$FILE_ID" |
| 195 | + |
| 196 | +echo |
| 197 | +echo "DONE" |
0 commit comments