#!/bin/bash # 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/ SESSION_COUNT=$(screen -ls | grep -c "\.shurikenpi.io") #!/bin/bash r(){ p $1 read -p " › " $2 } p() { echo -e " » $1" } p_user() { echo -e " › $1" } p_err(){ echo -e " \033[31m»\033[0m $1" } p_fatal(){ echo -e " \033[31m» $1\033[0m" } p_ok(){ echo -e " \033[32m»\033[0m $1" } p_warn(){ echo -e " \033[33m!\033[0m $1" } gum(){ ~/go/bin/gum $@ } msg() { echo "" echo -e "$(cat ../Messages/$1)" echo "" } ask_yes_or_no(){ echo -e " \033[33m?\033[0m $1" result=$(gum choose --cursor=  ›  Yes No) if [[ $result == "Yes" ]]; then p_user "Yes" return 0 fi p_user "No" return 1 } spin_it(){ local msg=$1 shift local command=$@ local hash=$(echo -n "$command" | md5sum | awk '{print $1}') local logfile="$TMP_DIRECTORY/$hash.txt" "$@" > $logfile 2>&1 & chars=(" ⠋ " " ⠙ " " ⠹ " " ⠸ " " ⠼ " " ⠴ " " ⠦ " " ⠧ " " ⠇ " " ⠏ ") pid=$! while kill -0 $pid 2> /dev/null; do for char in "${chars[@]}"; do echo -ne "\r$char" sleep 0.1 done done wait $pid exit_status=$? echo -ne "\r\033[K" if [ $exit_status -eq 0 ]; then p $msg else p_fatal "$msg [FATAL ERROR]" p_fatal "--- BEGIN ERROR DUMP ---" awk '{print " \033[31m " $0 "\033[0m"}' $logfile p_fatal "--- END ERROR DUMP ---" exit 1 fi if [ $VERBOSE -eq 1 ]; then awk '{print " ‣ " $0}' $logfile echo "" fi } install_prerequisites(){ p "Installing pre-requisites..." spin_it "goland-go (1/6)" sudo apt-get install -y golang-go spin_it "gum       (2/6)" go install github.com/charmbracelet/gum@latest spin_it "git       (3/6)" sudo apt-get install -y git spin_it "tor       (4/6)" sudo apt-get install -y tor spin_it "curl      (5/6)" sudo apt-get install -y curl spin_it "screen    (6/6)" sudo apt-get install -y screen } 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