From 93ee33d6f4a45afe0a8947117df92ec413a82251 Mon Sep 17 00:00:00 2001 From: clearkimura Date: Fri, 30 Dec 2016 20:53:29 +0800 Subject: [PATCH 1/7] Update INSTALL Initial clean up for optimization --- INSTALL | 93 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/INSTALL b/INSTALL index 223df81..e1d6525 100644 --- a/INSTALL +++ b/INSTALL @@ -15,10 +15,8 @@ # the Terminal. Else download and run: chmod +x INSTALL && ./INSTALL # -# FUNCTIONS FOR ACTION: - -function install_req { -echo "*** Install dependencies..." ### STEP 1 ### +# FUNCTIONS FOR DIRECT ACTION: +function install_req { ### STEP 1 ### ##################################################################### sudo apt-get install git build-essential fakeroot make binutils g++ \ python python-dev python-qt4 pyqt4-dev-tools squashfs-tools \ @@ -28,52 +26,69 @@ debhelper qt4-dev-tools qt4-linguist-tools \ ##################################################################### } -function download_src { -echo "*** Download source and extract..." ### STEP 2 ### +function download_src { ### STEP 2 ### ##################################################################### wget https://github.com/clearkimura/Customizer/archive/master.tar.gz tar zxvf master.tar.gz ##################################################################### } -function install_bin { -echo "*** Compile and install via dpkg..." ### STEP 3 ### +function install_bin { ### STEP 3 ### ##################################################################### cd Customizer-master && make deb cd && sudo dpkg --install customizer*.deb ##################################################################### } -function uninstall { -echo "*** Prepare to uninstall (or reinstall)..." ### PURGES ### +function uninstall { ### PURGES ### ##################################################################### sudo dpkg --purge customizer ##################################################################### -echo "*** Matching directories and files for deletion..." -ls -1d ?ustomizer* master.tar.gz* -echo "[!] User consent is required [y to confirm, else will skip]" -rm -I --verbose --recursive ?ustomizer* master.tar.gz* +} + +# FUNCTIONS FOR SUPPORT ACTION: +function clean { + echo "Matching files for deletion..." + ls -1d ?ustomizer* master.tar.gz* + echo "[!] User consent is required [y to confirm, else skip]" + rm -I --verbose --recursive ?ustomizer* master.tar.gz* } function renew_sh { -echo "[!] This action will rename existing script as *.old file then" -echo "[!] will download new script from GitHub and make executable" -echo "Press any key to continue [^C to cancel and exit]" && read -n 1 -echo "*** Rename and overwrite existing script..." -mv INSTALL customizer-INSTALL.old -echo "*** Download new INSTALL script..." -wget --quiet $(echo $URLH$URL1) -echo "*** Enable executable bit for new INSTALL script..." -chmod +x INSTALL -echo "[!] Run ./INSTALL again to use new script" + mv INSTALL customizer-INSTALL.old + wget --quiet $URLR1 + chmod +x INSTALL + echo "[!] Run ./INSTALL again to use new script" } -# FUNCTIONS FOR DISPLAY: +# FUNCTIONS FOR CHOICE: +function choice_1 { + echo "*** This will install dependencies and $NAME" + install_req && download_src && install_bin +} + +function choice_2 { + echo "*** This will install $NAME only" + uninstall && download_src && install_bin +} +function choice_3 { + echo "*** This will uninstall $NAME" + uninstall && clean +} + +function choice_s { + echo "*** This is only useful whenever the script had changes" + echo "*** on GitHub. Else, do not misuse this choice." + echo "Press any key to continue [^C to abort]" && read -n 1 + renew_sh +} + +# FUNCTIONS FOR DISPLAY: function show_msg { if [ "$KEY" != q ] then echo "Started INSTALL script" - echo "This script is compatible for $HINT" + echo "Use this script for $HINT" else echo "Finished now" && sleep 1 fi } @@ -81,31 +96,31 @@ function show_msg { function show_menu { echo && echo "What is your action?" echo " 1: i: New installation" - echo " s: Renew INSTALL script" + echo " s: Download new script, if any" echo " 2: r: Download source and reinstall" echo " 3: u: Uninstall" } -# SET VARIABLES: - -HINT="Customizer \"old stable\"" -KEY="0" -URLH="https://raw.githubusercontent.com/" -URL1="clearkimura/Customizer/master/INSTALL" +# VARIABLES FOR GLOBAL USE: +declare KEY="0" +declare -r NAME="customizer" +declare -r HINT="Customizer \"old stable\"" +declare -r REPO="clearkimura/Customizer" +declare -r URLR="https://raw.githubusercontent.com" +declare -r URLR1="$URLR/$REPO/master/INSTALL" # BEGIN SCRIPT: - show_msg while [ "$KEY" != q ] do { show_menu echo -n "Type your choice [q to quit]: " - read KEY + read -n 1 KEY && echo case $KEY in - 1|i) install_req && download_src && install_bin && KEY="q" ;; - 2|r) uninstall && download_src && install_bin && KEY="q" ;; - 3|u) uninstall && KEY="q" ;; - s) renew_sh && KEY="q" ;; + 1|i) choice_1 && KEY="q" ;; + 2|r) choice_2 && KEY="q" ;; + 3|u) choice_3 && KEY="q" ;; + s) choice_s && KEY="q" ;; q) echo "Do nothing"; break ;; *) echo "[?] Unknown option" ;; esac From f267195490f2145cc5cc322bed169b5e0e523742 Mon Sep 17 00:00:00 2001 From: clearkimura Date: Fri, 30 Dec 2016 21:05:19 +0800 Subject: [PATCH 2/7] Update INSTALL Check files to clean, else exit function --- INSTALL | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/INSTALL b/INSTALL index e1d6525..6c39c47 100644 --- a/INSTALL +++ b/INSTALL @@ -48,6 +48,11 @@ sudo dpkg --purge customizer # FUNCTIONS FOR SUPPORT ACTION: function clean { + echo "Check files to clean..." && sleep 1 + if [ -f master.tar.gz -o -d Customizer-master ] + then echo "Found in current directory: $PWD" + else return 0 + fi echo "Matching files for deletion..." ls -1d ?ustomizer* master.tar.gz* echo "[!] User consent is required [y to confirm, else skip]" From 384d9d45c4fb1d48acd93de455403b443f99848e Mon Sep 17 00:00:00 2001 From: clearkimura Date: Fri, 30 Dec 2016 21:16:05 +0800 Subject: [PATCH 3/7] Update INSTALL Be selective to proceed. wget will show any error message. Exit function if file was not downloaded. --- INSTALL | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/INSTALL b/INSTALL index 6c39c47..371e388 100644 --- a/INSTALL +++ b/INSTALL @@ -60,9 +60,18 @@ function clean { } function renew_sh { - mv INSTALL customizer-INSTALL.old - wget --quiet $URLR1 - chmod +x INSTALL + echo "Prepare to download script..." && sleep 1 + local -r FILE="$(basename $URLR1)" + if [ -f "$FILE" ] + then mv $FILE $NAME.sh.old && chmod -x $NAME.sh.old + else echo "Existing file was not found, skip rename" + fi + echo "Download will start..." + wget --no-verbose $URLR1 + if [ -f "$FILE" ] + then chmod +x $FILE + else echo "[!] File was not downloaded" && return 1 + fi echo "[!] Run ./INSTALL again to use new script" } From 58eed8a1b42f1b59ef21fd091043eaa1dc2b9f47 Mon Sep 17 00:00:00 2001 From: clearkimura Date: Fri, 30 Dec 2016 21:26:13 +0800 Subject: [PATCH 4/7] Update INSTALL Support uninstall via makefile, in case dpkg fails. Remove logical AND to run all actions for the choice. --- INSTALL | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/INSTALL b/INSTALL index 371e388..9a153c2 100644 --- a/INSTALL +++ b/INSTALL @@ -47,6 +47,22 @@ sudo dpkg --purge customizer } # FUNCTIONS FOR SUPPORT ACTION: +function uninstall_make { + echo "Check files to uninstall..." && sleep 1 + local -r BIN="/usr/sbin/customizer" + local -r FILE="Customizer-master" + if [ -f "$BIN" ] + then echo "$BIN still exist" + else return 0 + fi + echo "Uninstall via Makefile..." + if [ -d "$FILE" ] + then cd $FILE && sudo make uninstall + else echo "[?] Makefile was not found" && return 1 + fi + echo "[!] Uninstall may not be clean, next time use dpkg" +} + function clean { echo "Check files to clean..." && sleep 1 if [ -f master.tar.gz -o -d Customizer-master ] @@ -88,7 +104,9 @@ function choice_2 { function choice_3 { echo "*** This will uninstall $NAME" - uninstall && clean + uninstall + uninstall_make + clean } function choice_s { From d7e1bee42121cb239e28d3cefea29313ca99b409 Mon Sep 17 00:00:00 2001 From: clearkimura Date: Fri, 30 Dec 2016 22:38:05 +0800 Subject: [PATCH 5/7] Update INSTALL Be particular and selective before reinstall. Remove logical AND to run all actions for the choice. --- INSTALL | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/INSTALL b/INSTALL index 9a153c2..72c423e 100644 --- a/INSTALL +++ b/INSTALL @@ -69,12 +69,22 @@ function clean { then echo "Found in current directory: $PWD" else return 0 fi - echo "Matching files for deletion..." + echo "Matching files to remove..." ls -1d ?ustomizer* master.tar.gz* echo "[!] User consent is required [y to confirm, else skip]" rm -I --verbose --recursive ?ustomizer* master.tar.gz* } +function clean_part { + echo "Check particular files to clean..." && sleep 1 + if [ -d Customizer-master ] + then echo "Found in current directory: $PWD" + else return 0 + fi + echo "Remove selective directory and files without prompt" + rm --verbose --recursive ?ustomizer-master ?ustomizer*.deb +} + function renew_sh { echo "Prepare to download script..." && sleep 1 local -r FILE="$(basename $URLR1)" @@ -91,6 +101,32 @@ function renew_sh { echo "[!] Run ./INSTALL again to use new script" } +function renew_src { + echo "Prepare to download source..." && sleep 1 + local -r FILE="$(basename $URLS1)" + if [ -f "$FILE" ] + then mv $FILE $FILE.old && chmod -x $FILE.old + else echo "Existing file was not found, skip rename" + fi + echo "Download will start..." + wget --no-verbose $URLS1 + if [ -f "$FILE" ] + then tar zxf $FILE + else echo "[!] File was not downloaded" && return 1 + fi +} + +function renew_bin { + echo "Prepare to make binary..." && sleep 1 + local -r FILE="Customizer-master" + if [ -d "$FILE" ] + then cd $FILE && make deb 1>/dev/null && cd + else echo "[!] File was not extracted" && return 1 + fi + echo "Proceed to install binary..." + sudo dpkg --install customizer*.deb +} + # FUNCTIONS FOR CHOICE: function choice_1 { echo "*** This will install dependencies and $NAME" @@ -99,7 +135,9 @@ function choice_1 { function choice_2 { echo "*** This will install $NAME only" - uninstall && download_src && install_bin + clean_part + renew_src + renew_bin } function choice_3 { From 98427f37c97b38bf50c3212ddf9b729dfa950223 Mon Sep 17 00:00:00 2001 From: clearkimura Date: Fri, 30 Dec 2016 22:44:39 +0800 Subject: [PATCH 6/7] Update INSTALL Add missing variables for support action. Note that 'URLS' (for standard or source files) and 'URLR' (for raw files) are different. --- INSTALL | 2 ++ 1 file changed, 2 insertions(+) diff --git a/INSTALL b/INSTALL index 72c423e..442b36c 100644 --- a/INSTALL +++ b/INSTALL @@ -176,6 +176,8 @@ declare KEY="0" declare -r NAME="customizer" declare -r HINT="Customizer \"old stable\"" declare -r REPO="clearkimura/Customizer" +declare -r URLS="https://github.com" +declare -r URLS1="$URLS/$REPO/archive/master.tar.gz" declare -r URLR="https://raw.githubusercontent.com" declare -r URLR1="$URLR/$REPO/master/INSTALL" From 418ecab53b5a8b592f4f6204b1832043d83fb40b Mon Sep 17 00:00:00 2001 From: clearkimura Date: Sat, 31 Dec 2016 00:01:02 +0800 Subject: [PATCH 7/7] Update INSTALL Be sure to prevent "false positive" new installation. Also prevent users who had already installed binary. --- INSTALL | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/INSTALL b/INSTALL index 442b36c..77875d0 100644 --- a/INSTALL +++ b/INSTALL @@ -47,6 +47,17 @@ sudo dpkg --purge customizer } # FUNCTIONS FOR SUPPORT ACTION: +function ensure_new { + echo "Check files before install..." && sleep 1 + if [ -f master.tar.gz ] + then echo "[!] Source was found, wrong choice" && return 1 + fi + if [ -f /usr/sbin/customizer ] + then echo "[!] Binary was found, wrong choice" && return 1 + fi + echo "Proceed to install..." +} + function uninstall_make { echo "Check files to uninstall..." && sleep 1 local -r BIN="/usr/sbin/customizer" @@ -130,6 +141,7 @@ function renew_bin { # FUNCTIONS FOR CHOICE: function choice_1 { echo "*** This will install dependencies and $NAME" + ensure_new || return 1 install_req && download_src && install_bin }