diff --git a/get-androidfilehost.sh b/get-androidfilehost.sh new file mode 100755 index 0000000000000000000000000000000000000000..4f54b16c06a4bcbbb35cd69a7dadaa5ef283f52d --- /dev/null +++ b/get-androidfilehost.sh @@ -0,0 +1,101 @@ +#!/bin/bash + +# Copyright (C) 2019 ECORP SAS - Author: Romain Hunault +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Parameter +# $1: ANDROIDFILEHOST_ARCHIVE_URL +# $2: ANDROIDFILEHOST_FOLDER (will be created if doesn't exist) + +# Exit status +# - 0 : /e/ downloaded +# - 1 : Generic error code (see wget exit status here: https://www.gnu.org/software/wget/manual/html_node/Exit-Status.html) +# - 2 : Parse error—for instance, when parsing command-line options, the ‘.wgetrc’ or ‘.netrc’... (see wget exit status here: https://www.gnu.org/software/wget/manual/html_node/Exit-Status.html) +# - 3 : File I/O error (see wget exit status here: https://www.gnu.org/software/wget/manual/html_node/Exit-Status.html) +# - 4 : Network failure (see wget exit status here: https://www.gnu.org/software/wget/manual/html_node/Exit-Status.html) +# - 5 : SSL verification failure (see wget exit status here: https://www.gnu.org/software/wget/manual/html_node/Exit-Status.html) +# - 6 : Username/password authentication failure (see wget exit status here: https://www.gnu.org/software/wget/manual/html_node/Exit-Status.html) +# - 7 : Protocol errors (see wget exit status here: https://www.gnu.org/software/wget/manual/html_node/Exit-Status.html) +# - 8 : Server issued an error response (see wget exit status here: https://www.gnu.org/software/wget/manual/html_node/Exit-Status.html) +# - 10: No internet connection +# - 11: Invalid file downloaded +# - 101 : ANDROIDFILEHOST_ARCHIVE_URL missing +# - 102 : ANDROIDFILEHOST_FOLDER missing + +ANDROIDFILEHOST_ARCHIVE_URL=$1 +ANDROIDFILEHOST_FOLDER=$2 + +function check_md5sum () { + + echo "Check MD5SUM" + + FILE_ID=$1 + FILE_MD5_CHECKSUM=$2 + + curl 'https://androidfilehost.com/?fid='${FILE_ID} -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3' --compressed -H 'Referer: https://forum.xda-developers.com/galaxy-s9/samsung-galaxy-s9--s9-cross-device-development/twrp-exynos-t3763464' -H 'DNT: 1' -H 'Connection: keep-alive' -H $'Cookie: UTGv2=h4983524ab157374df94cc761ef73be85b70; CookieConsent={stamp:\'csW+0Aawj1W6ZMT4uWQanbx3DTe2sCrqs92Ip4HDhJy8avDOk2UUOw==\'%2Cnecessary:true%2Cpreferences:true%2Cstatistics:true%2Cmarketing:true%2Cver:2}; SPSI=b30cb85e78c681802c3d5fac79b44a57; afh=3be1e70712a60dafd5b6d31d77a3da2d; PRLST=XT; DSR=z6qqi2Hd/HniLiqH20k5BdYaMnXhLxC5PbVJiuucTClMmhOZ5wg+TOOuGXLJRc4tWWDIEBPHjZSnnodsWDIxOw==; DCSS=086342F4FAC33D11EFB678A1E206AC6CD490112; DGCC=Vx; DCST=pE9; adOtr=bc38beO75c8' -H 'Upgrade-Insecure-Requests: 1' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache' -H 'TE: Trailers' | grep ${FILE_MD5_CHECKSUM} + + exit $? +} + +if ! ping -c 1 gitlab.e.foundation 2>&1 >/dev/null +then + exit 10 +fi + +if [ -z ${ANDROIDFILEHOST_FOLDER} ] +then + exit 101 +fi + +if [ -z ${ANDROIDFILEHOST_ARCHIVE_URL} ] +then + exit 102 +fi + +mkdir -p ${ANDROIDFILEHOST_FOLDER} +FILENAME=$(basename ${ANDROIDFILEHOST_ARCHIVE_URL}) +FILE_ID=$(echo $ANDROIDFILEHOST_ARCHIVE_URL | sed 's/.*\/\(.*\)\/.*\.zip/\1/') +## URL_archive: https://qc1.androidfilehost.com/dl/xZsqRpunddhlcq1PO6SVlQ/1559982137/962187416754474353/no-verity-opt-encrypt-samsung-1.0.zip + +if [ -f ${ANDROIDFILEHOST_FOLDER}/${FILENAME} ] && [ -f ${ANDROIDFILEHOST_FOLDER}/${FILENAME}.md5sum ] +then + + + FILE_MD5_CHECKSUM=$(cat ${ANDROIDFILEHOST_FOLDER}/${FILENAME}.md5sum | sed 's/\(.*\) .*/\1/') + + check_md5sum ${FILE_ID} ${FILE_MD5_CHECKSUM} + + SUM_OK=$? + if [ ${SUM_OK} = 0 ] + then + exit 0 + fi + +fi + +wget -O ${ANDROIDFILEHOST_FOLDER}/${FILENAME} ${ANDROIDFILEHOST_ARCHIVE_URL} + +md5sum ${ANDROIDFILEHOST_FOLDER}/${FILENAME} > ${ANDROIDFILEHOST_FOLDER}/${FILENAME}.md5sum + +FILE_MD5_CHECKSUM=$(cat ${ANDROIDFILEHOST_FOLDER}/${FILENAME}.md5sum | sed 's/\(.*\) .*/\1/') + +check_md5sum ${FILE_ID} ${FILE_MD5_CHECKSUM} + +SUM_OK=$? +if [ ${SUM_OK} != 0 ] +then + rm ${FILENAME} + exit 11 +fi diff --git a/install-e.sh b/install-from-recovery.sh similarity index 79% rename from install-e.sh rename to install-from-recovery.sh index cf9dbb8f9d80cf0c5db8aff65ef5f83c22a500fc..c9fd699462e08c2d3e4195d687fbab1df4d7714f 100755 --- a/install-e.sh +++ b/install-from-recovery.sh @@ -17,7 +17,7 @@ # Parameter # $1: DEVICE_ID device identifier -# $2: E_ARCHIVE_PATH path to the /e/ archive to flash +# $2: ARCHIVE_PATH path to the /e/ archive to flash # Exit status # - 0 : /e/ installed @@ -25,18 +25,18 @@ # - 2 : Problems occurred during file transfer # - 3 : Problems occurred /e/ installation # - 101 : DEVICE_ID missing -# - 102 : E_ARCHIVE_PATH missing +# - 102 : ARCHIVE_PATH missing DEVICE_ID=$1 -E_ARCHIVE_PATH=$2 -E_IMAGE=$(basename $2) +ARCHIVE_PATH=$2 +ARCHIVE_NAME=$(basename $2) if [ -z $DEVICE_ID ] then exit 101 fi -if [ -z $E_ARCHIVE_PATH ] +if [ -z $ARCHIVE_PATH ] then exit 102 fi @@ -44,16 +44,16 @@ fi adb -s ${DEVICE_ID} shell twrp wipe system adb -s ${DEVICE_ID} shell twrp wipe cache adb -s ${DEVICE_ID} shell twrp wipe data -adb -s ${DEVICE_ID} push ${E_ARCHIVE_PATH} /sdcard +adb -s ${DEVICE_ID} push ${ARCHIVE_PATH} /sdcard if [ $? != 0 ] ; then exit 2 ; fi -adb -s ${DEVICE_ID} shell twrp install /sdcard/${E_IMAGE} +adb -s ${DEVICE_ID} shell twrp install /sdcard/${ARCHIVE_NAME} if [ $? != 0 ] ; then exit 3 ; fi sleep 1 -adb -s ${DEVICE_ID} shell rm /sdcard/${E_IMAGE} +adb -s ${DEVICE_ID} shell rm /sdcard/${ARCHIVE_NAME} sleep 1 diff --git a/wait-recovery.sh b/wait-recovery.sh index c96163be3b1a7c05995630d5250782a7da94d9d6..f3147e6644d6f73a325ed37c99816d1e726d6001 100755 --- a/wait-recovery.sh +++ b/wait-recovery.sh @@ -19,6 +19,7 @@ # Parameter # $1: DEVICES_LOCKED_PATH temp folder where are stored locked devices +# $2: DEVICE_ID ID of the device to wait # Return # - displayed: DEVICE_ID device detected @@ -29,12 +30,24 @@ # - 101 : DEVICES_LOCKED_PATH missing DEVICES_LOCKED_PATH=$1 +DEVICE_ID=$2 if [ -z $DEVICES_LOCKED_PATH ] then exit 101 fi +if [ ! -z $DEVICE_ID ] +then + while true + do + adb devices | grep --perl-regex "${DEVICE_ID}\trecovery" + if [ $? == 0 ] + then + exit 0 + fi + done +fi function newDevice {