lets just call this a git init okay?
This commit is contained in:
278
install.sh
278
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
|
||||
# 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
|
Reference in New Issue
Block a user