From 98e229c3d9439d4fe4bc4e215b3523774cdeb601 Mon Sep 17 00:00:00 2001 From: urban Date: Mon, 28 Aug 2023 05:59:26 +0200 Subject: [PATCH] update install script, move more constant to global vars --- Scripts/create_configuration.sh | 6 ++ Scripts/global.sh | 24 +++++++ Scripts/installer.sh | 56 +++++------------ Scripts/utils.sh | 2 +- build.sh | 24 ++++--- install.sh | 107 +++++++++++++++++++++++++++++++- 6 files changed, 169 insertions(+), 50 deletions(-) create mode 100755 Scripts/create_configuration.sh create mode 100644 Scripts/global.sh diff --git a/Scripts/create_configuration.sh b/Scripts/create_configuration.sh new file mode 100755 index 0000000..91ecdec --- /dev/null +++ b/Scripts/create_configuration.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +source ./global.sh +source ./utils.sh + +p "create new config" diff --git a/Scripts/global.sh b/Scripts/global.sh new file mode 100644 index 0000000..19172fa --- /dev/null +++ b/Scripts/global.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +VERBOSE=0 +while getopts ":v" option; do + case "${option}" in + v) + VERBOSE=1 + ;; + *) + echo "Usage: $0 [-v]" + exit 1 + ;; + esac +done + +LOGS=/dev/null +INSTALLATION_FOLDER="$HOME/shurikenpi" +GIT_FOLDER="$HOME/shurikenpi/shurikenpi.io" +TMP_DIRECTORY=/tmp/shuriken_io + +rm -fr $TMP_DIRECTORY 2>&1 +mkdir $TMP_DIRECTORY 2>&1 + +GIT_URL=https://github.com/Urban-Hacker/shurikenpi.io/ \ No newline at end of file diff --git a/Scripts/installer.sh b/Scripts/installer.sh index af1e0b3..35326fa 100644 --- a/Scripts/installer.sh +++ b/Scripts/installer.sh @@ -2,31 +2,30 @@ install_prerequisites(){ p "Installing pre-requisites..." spin_it "goland-go (1/5)" sudo apt-get install -y golang-go - spin_it "gum       (2/5)" go install github.com/charmbracelet/gum@latest && sleep 0.1 - spin_it "git       (3/5)" sudo apt-get install -y git && sleep 0.1 - spin_it "tor       (4/5)" sudo apt-get install -y tor && sleep 0.1 - spin_it "curl      (5/5)" sudo apt-get install -y curl && sleep 0.1 + spin_it "gum       (2/5)" go install github.com/charmbracelet/gum@latest + spin_it "git       (3/5)" sudo apt-get install -y git + spin_it "tor       (4/5)" sudo apt-get install -y tor + spin_it "curl      (5/5)" sudo apt-get install -y curl } go_to_install_directory(){ echo "" - cd ~ - local install_folder="$(pwd)/shurikenpi" - p "Install directory will be: $install_folder" - if [ -d $install_folder ]; then + cd $INSTALLATION_FOLDER + p "Install directory will be: $INSTALLATION_FOLDER" + if [ -d $INSTALLATION_FOLDER ]; then echo "" p_warn "An existing installation of ShurikenPi was detected!" ask_yes_or_no "Would you like to re-install ShurikenPi and wipe the existing installation?" local result=$? if [ $result == 0 ]; then - rm -fr $install_folder + rm -fr $INSTALLATION_FOLDER else p_err "Fatal: Aborting the installation script now" exit 1 fi fi - mkdir $install_folder - cd $install_folder + mkdir $INSTALLATION_FOLDER + cd $INSTALLATION_FOLDER } check_if_root(){ @@ -51,12 +50,12 @@ check_if_root(){ } do_update() { - spin_it "Updating, please wait..." sudo apt update + spin_it "Updating, please wait..." sudo apt-get update } check_if_upgrade(){ - UPGRADABLE_COUNT=$(apt list --upgradable 2>/dev/null | grep -c ^) + UPGRADABLE_COUNT=$(apt list --upgradable 2>$LOGS| grep -c ^) if (( UPGRADABLE_COUNT > 0 )); then p_warn "There are $UPGRADABLE_COUNT packages that can be upgraded." p_warn "It is recommended to run 'sudo apt upgrade' after ShurikenPi installation" @@ -66,32 +65,9 @@ check_if_upgrade(){ } clone_repository(){ - spin_it "Downloading ShurikenPi, please wait..." git clone https://github.com/Urban-Hacker/shurikenpi.io/ + spin_it "Downloading ShurikenPi, please wait..." git clone $GIT_URL } -create_tmp_log_directory() { - rm -fr /tmp/shuriken 2>&1 - mkdir /tmp/shuriken 2>&1 -} - - -VERBOSE=0 - -# check if -v is passed as argument -while getopts ":v" option; do - case "${option}" in - v) - VERBOSE=1 - ;; - *) - echo "Usage: $0 [-v]" - exit 1 - ;; - esac -done - -create_tmp_log_directory - # Entry point check_if_root do_update @@ -99,6 +75,6 @@ install_prerequisites check_if_upgrade go_to_install_directory clone_repository -cd ./shuriken/Tools/ -chmod +x dependencies.sh -./dependencies.sh \ No newline at end of file + +cd $GIT_FOLDER/Scripts/ +./create_configuration.sh \ No newline at end of file diff --git a/Scripts/utils.sh b/Scripts/utils.sh index 853698b..beb35f7 100644 --- a/Scripts/utils.sh +++ b/Scripts/utils.sh @@ -50,7 +50,7 @@ spin_it(){ shift local command=$@ local hash=$(echo -n "$command" | md5sum | awk '{print $1}') - local logfile="/tmp/shuriken/$hash.txt" + local logfile="$TMP_DIRECTORY/$hash.txt" "$@" > $logfile 2>&1 & chars=(" ⠋ " " ⠙ " " ⠹ " " ⠸ " " ⠼ " " ⠴ " " ⠦ " " ⠧ " " ⠇ " " ⠏ ") pid=$! diff --git a/build.sh b/build.sh index f78fb19..550643b 100755 --- a/build.sh +++ b/build.sh @@ -1,12 +1,20 @@ #!/bin/bash +build_installer(){ + # Header + echo "#!/bin/bash" > install.sh + echo "# File generated automatically by build.sh. Do not modify" >> install.sh + echo "# DO NOT MODIFY" >> install.sh + echo "" >> install.sh + + cat Scripts/global.sh >> install.sh + echo -e "\n\n" >> install.sh + cat Scripts/utils.sh >> install.sh + echo -e "\n\n" >> install.sh + cat Scripts/installer.sh >> install.sh + chmod +x install.sh +} + echo -e "Script to build Shuriken" -echo "#!/bin/bash" > install.sh -echo "# File generated automatically by build.sh. Do not modify" >> install.sh -echo "# DO NOT MODIFY" >> install.sh -echo "" >> install.sh -cat Scripts/utils.sh >> install.sh -echo -e "\n\n" >> install.sh -cat Scripts/installer.sh >> install.sh -chmod +x install.sh +build_installer echo "Finished" \ No newline at end of file diff --git a/install.sh b/install.sh index c86c0ab..7bd2c94 100755 --- a/install.sh +++ b/install.sh @@ -2,6 +2,32 @@ # File generated automatically by build.sh. Do not modify # DO NOT MODIFY +#!/bin/bash + +VERBOSE=0 +while getopts ":v" option; do + case "${option}" in + v) + VERBOSE=1 + ;; + *) + echo "Usage: $0 [-v]" + exit 1 + ;; + esac +done + +LOGS=/dev/null +INSTALLATION_FOLDER="$HOME/shurikenpi" +GIT_FOLDER="$HOME/shurikenpi/shurikenpi.io" +TMP_DIRECTORY=/tmp/shuriken_io + +rm -fr $TMP_DIRECTORY 2>&1 +mkdir $TMP_DIRECTORY 2>&1 + +GIT_URL=https://github.com/Urban-Hacker/shurikenpi.io/ + + #!/bin/bash p() { @@ -54,7 +80,7 @@ spin_it(){ shift local command=$@ local hash=$(echo -n "$command" | md5sum | awk '{print $1}') - local logfile="/tmp/shuriken/$hash.txt" + local logfile="$TMP_DIRECTORY/$hash.txt" "$@" > $logfile 2>&1 & chars=(" ⠋ " " ⠙ " " ⠹ " " ⠸ " " ⠼ " " ⠴ " " ⠦ " " ⠧ " " ⠇ " " ⠏ ") pid=$! @@ -84,3 +110,82 @@ spin_it(){ +install_prerequisites(){ + p "Installing pre-requisites..." + spin_it "goland-go (1/5)" sudo apt-get install -y golang-go + spin_it "gum       (2/5)" go install github.com/charmbracelet/gum@latest + spin_it "git       (3/5)" sudo apt-get install -y git + spin_it "tor       (4/5)" sudo apt-get install -y tor + spin_it "curl      (5/5)" sudo apt-get install -y curl +} + +go_to_install_directory(){ + echo "" + cd $INSTALLATION_FOLDER + p "Install directory will be: $INSTALLATION_FOLDER" + if [ -d $INSTALLATION_FOLDER ]; then + echo "" + p_warn "An existing installation of ShurikenPi was detected!" + ask_yes_or_no "Would you like to re-install ShurikenPi and wipe the existing installation?" + local result=$? + if [ $result == 0 ]; then + rm -fr $INSTALLATION_FOLDER + else + p_err "Fatal: Aborting the installation script now" + exit 1 + fi + fi + mkdir $INSTALLATION_FOLDER + cd $INSTALLATION_FOLDER +} + +check_if_root(){ + echo "" + p "Root user check..." + + if [[ $EUID -ne 0 ]]; then + echo "" + echo -e " ShurikenPi called with non-root priviledeges \033[31m:(\033[0m" + echo -e " Elevated priviledeges are required to install and run ShurikenPi" + echo -e " Please check the installer for any concerns about this requirement" + echo -e " Make sure you downloaded this script from a trusted source" + echo "" + if sudo true; then + p "Correct password." + else + p_err "Wrong password. Exiting." + exit 1 + fi + fi + p_ok "We are root :)" +} + +do_update() { + spin_it "Updating, please wait..." sudo apt-get update +} + +check_if_upgrade(){ + + UPGRADABLE_COUNT=$(apt list --upgradable 2>$LOGS| grep -c ^) + if (( UPGRADABLE_COUNT > 0 )); then + p_warn "There are $UPGRADABLE_COUNT packages that can be upgraded." + p_warn "It is recommended to run 'sudo apt upgrade' after ShurikenPi installation" + else + p "All packages are up to date." + fi +} + +clone_repository(){ + spin_it "Downloading ShurikenPi, please wait..." git clone $GIT_URL +} + +# Entry point +check_if_root +do_update +install_prerequisites +check_if_upgrade +go_to_install_directory +clone_repository + +cd $GIT_FOLDER/Scripts/ +./create_configuration.sh \ No newline at end of file