372 lines
8.7 KiB
Bash
Executable File
372 lines
8.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# set -e
|
|
set -u
|
|
|
|
# FUNCTIONS
|
|
create_app_folder() {
|
|
# create at home dir
|
|
cd $homedir
|
|
|
|
if [[ ! -d "Applications" ]]; then
|
|
sudo -u $SUDO_USER mkdir Applications
|
|
fi
|
|
|
|
# go back to install folder
|
|
cd $dir
|
|
}
|
|
|
|
zsh_prompt() {
|
|
|
|
if [[ $usezsh == "" ]]; then
|
|
# selection menu for zsh
|
|
printf %s "$YELLOW"
|
|
|
|
zshOption=""
|
|
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 zshOption
|
|
|
|
# check for valid input
|
|
while [ ${zshOption,,} != "y" ] && [ ${zshOption,,} != "n" ]; do
|
|
echo "Invalid input. Please press 'y' or 'n'"
|
|
read zshOption
|
|
done
|
|
|
|
printf %s "$RESET"
|
|
elif [[ $usezsh == "bash" ]]; then
|
|
zshOption="n"
|
|
elif [[ $usezsh == "zsh" ]]; then
|
|
zshOption="y"
|
|
fi
|
|
|
|
# run option
|
|
if [[ ${zshOption,,} = "y" ]]; then
|
|
# Create temporary zsh file
|
|
touch $homedir/.tempzshrc
|
|
|
|
# set up the basics of zsh
|
|
sh src/services/zsh/zsh.sh
|
|
fi
|
|
}
|
|
|
|
get_files() {
|
|
|
|
# Create temp place where files will be stored
|
|
cd src/importantinstalls
|
|
> ../temp/importantinstalls.txt
|
|
> ../temp/installations.txt
|
|
|
|
# File info
|
|
applications=""
|
|
counter=0
|
|
|
|
|
|
for file in *; do
|
|
# Every .sh file in application folder will be noted in installations.txt
|
|
if [[ $file == *.sh ]]; then
|
|
echo "${file%.*}" >> ../temp/importantinstalls.txt
|
|
fi
|
|
done
|
|
|
|
cd ../applications
|
|
|
|
# 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() {
|
|
cd ../temp
|
|
|
|
if $downloadall; then
|
|
# remove all numbers from items
|
|
sed -i 's/[^ ]* //' installations.txt
|
|
clear
|
|
return
|
|
fi
|
|
|
|
printf %s "$YELLOW"
|
|
# Show all the options
|
|
echo "The following items will be installed."
|
|
echo "-------------Must install-------------"
|
|
cat importantinstalls.txt
|
|
echo "--------------------------------------"
|
|
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."
|
|
echo "-------------Must install-------------"
|
|
cat importantinstalls.txt
|
|
echo "--------------------------------------"
|
|
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
|
|
|
|
# Download important files
|
|
while read line; do
|
|
|
|
#Reading each line and execute file
|
|
if ! [ -x "$(command -v $line)" ]; then
|
|
sh ../importantinstalls/$line.sh
|
|
else
|
|
echo "$line is already installed"
|
|
fi
|
|
|
|
done < "importantinstalls.txt"
|
|
|
|
# Download the selected applications
|
|
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=$(($amount + "$(wc -l < importantinstalls.txt)"))
|
|
amount=$(($end / $amount))
|
|
|
|
# set design
|
|
print_logo
|
|
|
|
printf %s "$YELLOW"
|
|
echo "The following items are going to be installed:"
|
|
cat importantinstalls.txt
|
|
cat installations.txt
|
|
echo ""
|
|
printf %s "$RESET"
|
|
|
|
# download important files
|
|
while read line; do
|
|
printf %s "$YELLOW"
|
|
|
|
ProgressBar ${start} ${end} ${line}
|
|
#Reading each line and execute file
|
|
if ! [ -x "$(command -v $line)" ]; then
|
|
sh ../importantinstalls/$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 < "importantinstalls.txt"
|
|
|
|
# download selected applications
|
|
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
|
|
printf %s "$YELLOW"
|
|
ProgressBar ${number} ${end} "..."
|
|
printf %s "$RESET"
|
|
sleep 0.02
|
|
done
|
|
fi
|
|
|
|
fi
|
|
}
|
|
|
|
check_arguments() {
|
|
case $1 in
|
|
-h|--help) # display help
|
|
print_logo
|
|
print_help
|
|
exit 1
|
|
;;
|
|
-v|--version) # display help
|
|
print_version
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
check_sudo_arguments() {
|
|
check_arguments $@
|
|
|
|
while getopts ":abdz" option; do
|
|
case $option in
|
|
d) # enable debug
|
|
debug=true
|
|
;;
|
|
a) # enable all
|
|
downloadall=true
|
|
;;
|
|
z) # enable zsh
|
|
usezsh="zsh"
|
|
;;
|
|
b) # enable bash
|
|
usezsh="bash"
|
|
;;
|
|
*) # incorrect option
|
|
echo "Wrong argument given, please use '-h' to see what arguments are available."
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
main
|
|
}
|
|
|
|
install_oh_my_zsh() {
|
|
# run option
|
|
if [[ ${zshOption,,} = "y" ]]; then
|
|
# Run Ohmyzsh (ends script)
|
|
sh services/zsh/Oh-My-ZSH.sh
|
|
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/*
|
|
|
|
install_oh_my_zsh
|
|
}
|
|
|
|
# PROGRAM BODY
|
|
# Safe important paths
|
|
dir="$(pwd)"
|
|
|
|
# Make sure the code is runned in the right way
|
|
if [[ `basename "$dir"` != "installify" ]]; then
|
|
echo "Please run this script in the installify 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
|
|
downloadall=false
|
|
usezsh=""
|
|
echo $homedir
|
|
sleep 10
|
|
|
|
# run the program
|
|
if [ $# -eq 0 ]; then
|
|
main
|
|
else
|
|
check_sudo_arguments $@
|
|
fi |