Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix141 #151

Merged
7 commits merged into from
Dec 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 138 additions & 39 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -28,84 +26,185 @@ 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 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"
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 ]
then echo "Found in current directory: $PWD"
else return 0
fi
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 "[!] 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"
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"
}

# FUNCTIONS FOR DISPLAY:
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"
ensure_new || return 1
install_req && download_src && install_bin
}

function choice_2 {
echo "*** This will install $NAME only"
clean_part
renew_src
renew_bin
}

function choice_3 {
echo "*** This will uninstall $NAME"
uninstall
uninstall_make
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
}

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 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"

# 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
Expand Down