From 42f56d9af4164c3ddf24b9f2b7eb112950c581b0 Mon Sep 17 00:00:00 2001 From: Howard Wu <40033067+Howard20181@users.noreply.github.com> Date: Sat, 17 Sep 2022 21:23:18 +0800 Subject: [PATCH] Request root access only when all files are present in offline mode --- scripts/build.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index a5647fb..6f16406 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -275,6 +275,12 @@ if [ "$DEBUG" ]; then set -x fi +require_su() { + if [ "$(sudo whoami)" != "root" ]; then + sudo echo "sudo is required to run this script" + fi +} + declare -A RELEASE_NAME_MAP=(["retail"]="Retail" ["RP"]="Release Preview" ["WIS"]="Insider Slow" ["WIF"]="Insider Fast") RELEASE_NAME=${RELEASE_NAME_MAP[$RELEASE_TYPE]} || abort @@ -295,11 +301,10 @@ if [ "$GAPPS_BRAND" = "OpenGApps" ]; then else GAPPS_PATH="$DOWNLOAD_DIR"/MindTheGapps-"$ARCH".zip fi -if [ "$(sudo whoami)" != "root" ]; then - sudo echo "sudo is required to run this script" -fi + if [ -z "${OFFLINE+x}" ]; then trap 'rm -f -- "${DOWNLOAD_DIR:?}/${DOWNLOAD_CONF_NAME}"' EXIT + require_su echo "Generate Download Links" python3 generateWSALinks.py "$ARCH" "$RELEASE_TYPE" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" || abort if [ -z "${CUSTOM_MAGISK+x}" ]; then @@ -332,6 +337,7 @@ else echo "Offline mode: Some files are missing, please disable offline mode." exit 1 fi + require_su fi echo "Extract WSA"