From 4fc74ecbe3eba842bcc34bd58f79e8f3ef4d7d42 Mon Sep 17 00:00:00 2001 From: spekulaas Date: Fri, 24 Sep 2021 16:48:53 +0200 Subject: [PATCH] lets just call this a git init okay? --- REDME.md | 29 +- install.sh | 278 ++++++++++++++++-- src/Oh-My-ZSH(TO-DO).sh | 2 + src/applications/BootstrapStudio.sh | 37 +++ src/applications/Firefox.sh | 2 + src/applications/Git.sh | 2 + src/applications/Node.sh | 3 + src/applications/NordVPN.sh | 4 + src/applications/OBS.sh | 2 + src/applications/Slack.sh | 3 + src/applications/VSCode.sh | 10 + src/applications/Yarn.sh | 3 + src/applications/gcc.sh | 1 + src/applications/openjdk.sh | 2 + src/applications/spotify.sh | 3 + .../applicationsTODO/AndroidStudio.sh | 0 src/applicationsTODO/Defold.sh | 1 + src/applicationsTODO/Discord.sh | 3 + src/applicationsTODO/Docker.sh | 1 + .../applicationsTODO/Python.sh | 0 src/applicationsTODO/Xampp.sh | 0 src/applicationsTODO/chromium.sh | 2 + src/services/connection.sh | 10 + src/services/help.sh | 62 ++++ src/services/loadbar.sh | 16 + src/temp/.gitignore | 0 26 files changed, 436 insertions(+), 40 deletions(-) create mode 100644 src/Oh-My-ZSH(TO-DO).sh create mode 100755 src/applications/BootstrapStudio.sh create mode 100644 src/applications/Firefox.sh create mode 100755 src/applications/Git.sh create mode 100644 src/applications/Node.sh create mode 100644 src/applications/NordVPN.sh create mode 100644 src/applications/OBS.sh create mode 100644 src/applications/Slack.sh create mode 100644 src/applications/VSCode.sh create mode 100644 src/applications/Yarn.sh create mode 100644 src/applications/gcc.sh create mode 100644 src/applications/openjdk.sh create mode 100644 src/applications/spotify.sh rename Applications/Defold.sh => src/applicationsTODO/AndroidStudio.sh (100%) create mode 100644 src/applicationsTODO/Defold.sh create mode 100644 src/applicationsTODO/Discord.sh create mode 100755 src/applicationsTODO/Docker.sh rename Applications/VSCode.sh => src/applicationsTODO/Python.sh (100%) create mode 100644 src/applicationsTODO/Xampp.sh create mode 100644 src/applicationsTODO/chromium.sh create mode 100644 src/services/connection.sh create mode 100755 src/services/help.sh create mode 100644 src/services/loadbar.sh create mode 100644 src/temp/.gitignore diff --git a/REDME.md b/REDME.md index bebe04b..37c5055 100644 --- a/REDME.md +++ b/REDME.md @@ -2,22 +2,31 @@ Simple Bash application installer. ## Applications & Software -* Visual Studio Code (TO-DO) -* Node (TO-DO) -* Java (TO-DO) * Android Studio (TO-DO) -* Discord (TO-DO) -* OBS (TO-DO) +* Bootstrap Studio +* Chromium (TO-DO) * Defold (TO-DO) -* Spotify (TO-DO) -* Slack (TO-DO) -* ZSH (TO-DO) +* Discord (TO-DO) * Docker (TO-DO) +* Firefox +* Gcc +* Git +* Node +* NordVPN +* OBS +* Python (TO-DO) +* Yarn +* Open-jdk +* Slack +* Spotify +* Visual Studio Code * Xampp (TO-DO) +* ZSH (TO-DO) * Missing any applications or software? Feel free to leave an issue behind or create a merge request with the created files :) -## Create -Add file name to array in install.sh file +## TO-DO +Name change BashInstaller -> Installify +See applications and software tab \ No newline at end of file diff --git a/install.sh b/install.sh index 092c06a..055868c 100755 --- a/install.sh +++ b/install.sh @@ -1,45 +1,263 @@ #!/usr/bin/env bash - -set -e +# set -e set -u +# FUNCTIONS +create_app_folder() { + # create at home dir + cd $homedir - -myfunc() { - local myresult='some value' - echo $myresult + if [[ ! -d "Applications" ]]; then + sudo -u $SUDO_USER mkdir Applications + fi + + # go back to install folder + cd $dir } -result="$(myfunc)" +zsh_prompt() { + # selection menu for zsh + printf %s "$YELLOW" + deleteOption="" + echo "Do you want Oh-My-ZSH as terminal extension?" + echo "To use 'Oh-My-ZSH' enter 'y' to to continue in bash enter 'n'" + read deleteOption - -get_files() { - cd Applications - local -n arr=$1 - local FILES=(one two) - - for file in "$PWD"/*; do - if [[ $file == ./install.sh ]]; then - echo "das" - elif [[ $file == *.sh ]]; then - - arr+=(${file##*/}) - fi + # check for valid input + while [ ${deleteOption,,} != "y" ] && [ ${deleteOption,,} != "n" ]; do + echo "Invalid input. Please press 'y' or 'n'" + read deleteOption done - echo ${FILES[@]} + printf %s "$RESET" + + # run option + if [[ ${deleteOption,,} = "n" ]]; then + return + elif [[ ${deleteOption,,} = "y" ]]; then + echo "nice choice lets use zsh" + fi } -# https://stackoverflow.com/questions/10582763/how-to-return-an-array-in-bash-without-using-globals -# get_files() -array=() -get_files array -# VAR+=("$(get_files)") +get_files() { + # Create temp place where files will be stored + cd src/applications + > ../temp/installations.txt -# echo "${VAR[-1]}" + # File info + applications="" + counter=0 -for i in "${arr[@]}"; do - echo $i -done \ No newline at end of file + # Write every file name into installations + for file in *; do + # Every .sh file in application folder will be noted in installations.txt + if [[ $file == *.sh ]]; then + counter=$(( $counter + 1 )) + echo "[$counter] ${file%.*}" >> ../temp/installations.txt + fi + done +} + +select_files() { + printf %s "$YELLOW" + # Show all the options + cd ../temp + echo "The following items will be installed." + cat installations.txt + + printf %s "$RESET" + + # Remove installations from file + echo + while read -p "${YELLOW}Select the number of the item you don't want to install (select '0' to continue): " input; do + + # Restart loop if wrong character is used + if [[ -n ${input//[0-9]/} ]]; then + echo "Please enter a valid number!" + continue + fi + + # Break the loop on input + if [[ $input == "0" || $input == "" ]]; then + clear + break + else + + # If pattern exist remove line + if grep -wq "$input" "installations.txt"; then + + # get the full text + a="$(grep -F [$input] installations.txt)" + + # reverse and remove full text + grep -Fv "$a" installations.txt > filename2; mv filename2 installations.txt + else + echo "Please try again" + fi + + clear + print_logo + + printf %s "$YELLOW" + echo "The following items will be installed." + cat installations.txt + echo + printf %s "$RESET" + + fi + done + + printf %s "$RESET" + # remove all numbers from items + sed -i 's/[^ ]* //' installations.txt +} + +install_files() { + # Check if debug is activated + if $debug; then + while read line; do + + #Reading each line and execute file + if ! [ -x "$(command -v $line)" ]; then + sh ../applications/$line.sh + else + echo "$line is already installed" + fi + + done < "installations.txt" + else + # set standard info + source ./../services/loadbar.sh + start=1 + end=100 + amount="$(wc -l < installations.txt)" + amount=$(($end / $amount)) + + # set design + print_logo + + printf %s "$YELLOW" + echo "The following items are going to be installed:" + cat installations.txt + echo "" + printf %s "$RESET" + + while read line; do + printf %s "$YELLOW" + + ProgressBar ${start} ${end} ${line} + #Reading each line and execute file + if ! [ -x "$(command -v $line)" ]; then + sh ../applications/$line.sh >> /dev/null 2>&1 + fi + + # update progressbar + reach=$(( $start + $amount )) + for number in $(seq ${start} ${reach}); do + ProgressBar ${number} ${end} ${line} + sleep 0.02 + done + printf %s "$RESET" + start=$reach + + done < "installations.txt" + + # Completing + if [[ $start != 100 ]]; then + for number in $(seq ${start} 100); do + ProgressBar ${number} ${end} "..." + sleep 0.02 + done + fi + + fi +} + +check_arguments() { + if [[ $1 = "-h" || $1 = "-help" ]]; then + print_logo + print_help + exit 1 + elif [[ $1 = "-v" || $1 = "-version" ]]; then + print_version + exit 1 + fi +} + +check_sudo_arguments() { + check_arguments $@ + + if [[ $1 = "-d" || $1 = "-debug" ]]; then + debug=true + main + fi +} + +main() { + # check if the computer has a stable connections + source ./src/services/connection.sh + check_connection + + # Create applications folder + create_app_folder + + # Print the logo + clear + print_logo + + # ZSH prompt + zsh_prompt + + # Print the logo + clear + print_logo + + # create file with all items + get_files + + # sort the file with the items + select_files + + # install the selected files + install_files + + # remove all files in temp + cd ~ + cd $dir + cd src + rm temp/* +} + +# PROGRAM BODY +# Safe important paths +dir="$(pwd)" + +# Make sure the code is runned in the right way +if [[ `basename "$dir"` != "BashInstaller" ]]; then + echo "Please run this script in the Bashinstaller folder." + exit 1 +fi + +# add help.sh +source ./src/services/help.sh +setup_color + +if [[ $EUID != 0 ]]; then + check_arguments $@ + echo "Please run this script with sudo. Run it like this:" + echo "sudo ./install.sh" + exit 1 +fi + +# Safe important variables +homedir="$(getent passwd $SUDO_USER | cut -d: -f6)" +debug=false + +# run the program +if [ $# -eq 0 ]; then + main +else + check_sudo_arguments $@ +fi \ No newline at end of file diff --git a/src/Oh-My-ZSH(TO-DO).sh b/src/Oh-My-ZSH(TO-DO).sh new file mode 100644 index 0000000..f3f8e5a --- /dev/null +++ b/src/Oh-My-ZSH(TO-DO).sh @@ -0,0 +1,2 @@ +sudo apt install zsh -y +sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" -y diff --git a/src/applications/BootstrapStudio.sh b/src/applications/BootstrapStudio.sh new file mode 100755 index 0000000..78f8e52 --- /dev/null +++ b/src/applications/BootstrapStudio.sh @@ -0,0 +1,37 @@ +# Get the full html and get the link of the button +wget https://bootstrapstudio.io/download +latestversionimage="$(grep -w 'data-linux="' "download")" +latestversionsh="$(grep -w 'data-linux-install="' "download")" + +# remove useless stuff of the link +latestversionimage=${latestversionimage#*'data-linux="'} +latestversionimage=${latestversionimage%'"'*} + +# remove useless stuff of the link +latestversionsh=${latestversionsh#*'"'} +latestversionsh=${latestversionsh%'"'*} + +# Safe the path +curdir="$(pwd)" +homedir="$(getent passwd $SUDO_USER | cut -d: -f6)" + +# go to app folder to safe the files +cd $homedir +cd Applications + +sudo -u $SUDO_USER mkdir BootstrapStudio +cd BootstrapStudio + +# get images +sudo -u $SUDO_USER wget https://bootstrapstudio.io/$latestversionimage +sudo -u $SUDO_USER wget https://bootstrapstudio.io/$latestversionsh + +# downloadd app +echo "y" | sudo -u $SUDO_USER bash launcher.sh + +# remove unnesesary files +rm launcher.sh + +# get back to main folder +cd ~ +cd $curdir \ No newline at end of file diff --git a/src/applications/Firefox.sh b/src/applications/Firefox.sh new file mode 100644 index 0000000..15e4208 --- /dev/null +++ b/src/applications/Firefox.sh @@ -0,0 +1,2 @@ +sudo apt-get update +sudo apt install firefox \ No newline at end of file diff --git a/src/applications/Git.sh b/src/applications/Git.sh new file mode 100755 index 0000000..cff54ab --- /dev/null +++ b/src/applications/Git.sh @@ -0,0 +1,2 @@ +sudo apt-get update +sudo apt-get install git \ No newline at end of file diff --git a/src/applications/Node.sh b/src/applications/Node.sh new file mode 100644 index 0000000..57267cd --- /dev/null +++ b/src/applications/Node.sh @@ -0,0 +1,3 @@ +curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - +./../applications/gcc.sh +sudo apt-get install -y nodejs \ No newline at end of file diff --git a/src/applications/NordVPN.sh b/src/applications/NordVPN.sh new file mode 100644 index 0000000..909a4d1 --- /dev/null +++ b/src/applications/NordVPN.sh @@ -0,0 +1,4 @@ +wget https://repo.nordvpn.com/deb/nordvpn/debian/pool/main/nordvpn-release_1.0.0_all.deb +sudo apt-get install ./nordvpn-release_1.0.0_all.deb +sudo apt-get update +sudo apt install nordvpn \ No newline at end of file diff --git a/src/applications/OBS.sh b/src/applications/OBS.sh new file mode 100644 index 0000000..641aa0f --- /dev/null +++ b/src/applications/OBS.sh @@ -0,0 +1,2 @@ +sudo apt update +sudo apt install obs-studio \ No newline at end of file diff --git a/src/applications/Slack.sh b/src/applications/Slack.sh new file mode 100644 index 0000000..07b09cd --- /dev/null +++ b/src/applications/Slack.sh @@ -0,0 +1,3 @@ +sudo snap install slack --classic +sudo apt-get update +sudo apt-get upgrade slack-desktop \ No newline at end of file diff --git a/src/applications/VSCode.sh b/src/applications/VSCode.sh new file mode 100644 index 0000000..f03d8d4 --- /dev/null +++ b/src/applications/VSCode.sh @@ -0,0 +1,10 @@ +# get package +wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg +sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/ +sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list' +rm -f packages.microsoft.gpg + +# install package +sudo apt install apt-transport-https +sudo apt update +sudo apt install code \ No newline at end of file diff --git a/src/applications/Yarn.sh b/src/applications/Yarn.sh new file mode 100644 index 0000000..35fb78e --- /dev/null +++ b/src/applications/Yarn.sh @@ -0,0 +1,3 @@ +curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - +echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list +sudo apt-get update && sudo apt-get install yarn \ No newline at end of file diff --git a/src/applications/gcc.sh b/src/applications/gcc.sh new file mode 100644 index 0000000..83d9e04 --- /dev/null +++ b/src/applications/gcc.sh @@ -0,0 +1 @@ +sudo apt-get install gcc g++ make \ No newline at end of file diff --git a/src/applications/openjdk.sh b/src/applications/openjdk.sh new file mode 100644 index 0000000..e9ba34f --- /dev/null +++ b/src/applications/openjdk.sh @@ -0,0 +1,2 @@ +sudo apt update +sudo apt install default-jdk \ No newline at end of file diff --git a/src/applications/spotify.sh b/src/applications/spotify.sh new file mode 100644 index 0000000..f8b8dfd --- /dev/null +++ b/src/applications/spotify.sh @@ -0,0 +1,3 @@ +curl -sS https://download.spotify.com/debian/pubkey_0D811D58.gpg | sudo apt-key add - +echo "deb http://repository.spotify.com stable non-free" | sudo tee /etc/apt/sources.list.d/spotify.list +sudo apt-get update && sudo apt-get install spotify-client -y \ No newline at end of file diff --git a/Applications/Defold.sh b/src/applicationsTODO/AndroidStudio.sh similarity index 100% rename from Applications/Defold.sh rename to src/applicationsTODO/AndroidStudio.sh diff --git a/src/applicationsTODO/Defold.sh b/src/applicationsTODO/Defold.sh new file mode 100644 index 0000000..14b1f75 --- /dev/null +++ b/src/applicationsTODO/Defold.sh @@ -0,0 +1 @@ +echo "defold" \ No newline at end of file diff --git a/src/applicationsTODO/Discord.sh b/src/applicationsTODO/Discord.sh new file mode 100644 index 0000000..21a5f86 --- /dev/null +++ b/src/applicationsTODO/Discord.sh @@ -0,0 +1,3 @@ +wget -O discord.deb "https://discordapp.com/api/download?platform=linux&format=deb" +sudo dpkg -i discord.deb +echo "y" | sudo apt install -f \ No newline at end of file diff --git a/src/applicationsTODO/Docker.sh b/src/applicationsTODO/Docker.sh new file mode 100755 index 0000000..4aa0434 --- /dev/null +++ b/src/applicationsTODO/Docker.sh @@ -0,0 +1 @@ +apt-get update \ No newline at end of file diff --git a/Applications/VSCode.sh b/src/applicationsTODO/Python.sh similarity index 100% rename from Applications/VSCode.sh rename to src/applicationsTODO/Python.sh diff --git a/src/applicationsTODO/Xampp.sh b/src/applicationsTODO/Xampp.sh new file mode 100644 index 0000000..e69de29 diff --git a/src/applicationsTODO/chromium.sh b/src/applicationsTODO/chromium.sh new file mode 100644 index 0000000..ab7f24c --- /dev/null +++ b/src/applicationsTODO/chromium.sh @@ -0,0 +1,2 @@ +sudo apt-get update +sudo apt install chromium -y \ No newline at end of file diff --git a/src/services/connection.sh b/src/services/connection.sh new file mode 100644 index 0000000..d59dd99 --- /dev/null +++ b/src/services/connection.sh @@ -0,0 +1,10 @@ +check_connection() { + wget -q --spider http://google.com + + if [ $? -ne 0 ]; then + echo "ERROR: NO INTERNET CONNECTION. Please make sure that there is a stable internet connection." + exit 1 + fi +} + +# check_connection \ No newline at end of file diff --git a/src/services/help.sh b/src/services/help.sh new file mode 100755 index 0000000..2f57fc3 --- /dev/null +++ b/src/services/help.sh @@ -0,0 +1,62 @@ +setup_color() { + # Only use colors if connected to a terminal + if [ -t 1 ]; then + RED=$(printf '\033[31m') + GREEN=$(printf '\033[32m') + YELLOW=$(printf '\033[33m') + BLUE=$(printf '\033[34m') + BOLD=$(printf '\033[1m') + RESET=$(printf '\033[m') + else + RED="" + GREEN="" + YELLOW="" + BLUE="" + BOLD="" + RESET="" + fi +} + +print_logo() { + # set color + printf %s "$YELLOW" + cat <<'EOF' +------------------------------------------------------------------------------- +------------------------------------------------------------------------------- +------------------------------------------------------------------------------- +------------------------------------------------------------------------------- +--- --- +---██ ███ ██ ███████ ████████ █████ ██ ██ ██ ███████ ██ ██--- +---██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ --- +---██ ██ ██ ██ ███████ ██ ███████ ██ ██ ██ █████ ████ --- +---██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ --- +---██ ██ ████ ███████ ██ ██ ██ ███████ ███████ ██ ██ ██ --- +--- --- +------------------------------------------------------------------------------- +-------------------------------made by spekulaas------------------------------- +---------------------------------Version 1.0.0--------------------------------- +------------------------------------------------------------------------------- + +EOF + # set color to default + printf %s "$RESET" +} + +print_help() { + # set color + printf %s "$YELLOW" + cat <<'EOF' +Usage: Sudo ./install.sh [command oprions] + +Command options: + -h, -help Show a list of all commands + -v, -version Show the current version of the application + -d, -debug Display all the download information +EOF + # set color to default + printf %s "$RESET" +} + +print_version() { + echo "Version 1.0.0" +} \ No newline at end of file diff --git a/src/services/loadbar.sh b/src/services/loadbar.sh new file mode 100644 index 0000000..3034ef6 --- /dev/null +++ b/src/services/loadbar.sh @@ -0,0 +1,16 @@ +ProgressBar() { +# Process data + program=(${3}) + + let _progress=(${1}*100/${2}*100)/100 + let _done=(${_progress}*4)/10 + let _left=40-$_done + # let _program=${3} + fill=$(printf "%${_done}s") + empty=$(printf "%${_left}s") + # program=$(printf "${_program}") + + printf "\rProgress : |${fill// /▇}${empty// / }| ${_progress}%%" + printf " Installing ${program} \r" + +} \ No newline at end of file diff --git a/src/temp/.gitignore b/src/temp/.gitignore new file mode 100644 index 0000000..e69de29