Upadting Installer
This commit is contained in:
19
installer/NEEDED-FOR-INSTALLER
Normal file
19
installer/NEEDED-FOR-INSTALLER
Normal file
@@ -0,0 +1,19 @@
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
|
||||
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
|
||||
|
||||
# Modular Bashrc
|
||||
mkdir -p ~/.bashrc.d/scripts-needed
|
||||
mkdir -p ~/.bashrc.d/scripts-enabled
|
||||
mkdir -p ~/.bashrc.d/scripts-available
|
||||
if [ -d ~/.bashrc.d ]; then
|
||||
for needed in ~/.bashrc.d/scripts-needed/*.sh; do
|
||||
[ -r "$needed" ] && source "$needed"
|
||||
done
|
||||
unset needed
|
||||
for file in ~/.bashrc.d/scripts-enabled/*.sh; do
|
||||
[ -r "$file" ] && source "$file"
|
||||
done
|
||||
unset file
|
||||
|
||||
fi
|
||||
181
installer/brc-script-install.sh
Normal file → Executable file
181
installer/brc-script-install.sh
Normal file → Executable file
@@ -1,5 +1,101 @@
|
||||
#!/bin/bash
|
||||
home="/home/$(whoami)"
|
||||
clear
|
||||
user=$(whoami) # Remove the extra space
|
||||
|
||||
follow() {
|
||||
read -p "Press 'Enter' to continue"
|
||||
}
|
||||
|
||||
loop2=0
|
||||
while [ $loop2 -lt 1 ]; do # Corrected the integer comparison
|
||||
echo "### brc-script installer ###"
|
||||
echo "---------------------------------------------"
|
||||
echo "Do you want to install for the current user ($user)?"
|
||||
echo "---------------------------------------------"
|
||||
echo " y - yes"
|
||||
echo " n - no"
|
||||
echo " q - exit"
|
||||
echo " default - yes"
|
||||
echo "---------------------------------------------"
|
||||
read choice
|
||||
if [ "$choice" == "n" ]; then
|
||||
loop2=1
|
||||
loop1=0
|
||||
clear
|
||||
while [ $loop1 -lt 1 ]; do # Corrected the integer comparison
|
||||
echo "----------------------------"
|
||||
echo "List of the available users:"
|
||||
echo "----------------------------"
|
||||
for i in $(grep -E ':/home/' /etc/passwd | cut -d: -f1); do echo $i; done
|
||||
echo "q = exit"
|
||||
echo "----------------------------"
|
||||
echo "Type the user:"
|
||||
read choice2
|
||||
if [ -d "/home/$choice2" ]; then
|
||||
user=$choice2
|
||||
echo "Selected user '$choice2'!"
|
||||
echo "-------------------"
|
||||
echo "Can you confirm it?"
|
||||
echo "-------------------"
|
||||
echo " y = yes "
|
||||
echo " n = no "
|
||||
echo " default = no "
|
||||
echo "-------------------"
|
||||
read confirm # Changed 'input' to 'read'
|
||||
if [ "$confirm" == "y" ]; then
|
||||
user=$choice2
|
||||
echo "Using user '$choice2'"
|
||||
loop1=1
|
||||
else
|
||||
echo "Wrong selection, for user '$choice2' "
|
||||
follow
|
||||
loop1=0
|
||||
fi
|
||||
elif [ "$choice2" == "q" ]; then
|
||||
echo "Exit from the installer script"
|
||||
exit 1
|
||||
else
|
||||
echo "Home folder for '$choice2' does not exist!"
|
||||
echo "Try with another one!"
|
||||
fi
|
||||
done
|
||||
elif [ "$choice" == "q" ]; then
|
||||
echo "[ Exit from the installer script! ]"
|
||||
exit 1
|
||||
else
|
||||
clear
|
||||
loop3=0
|
||||
while [ $loop3 -eq 0 ]; do
|
||||
echo "--------------------------------"
|
||||
echo "Do you want to use '$user' user?"
|
||||
echo "--------------------------------"
|
||||
echo " y = yes"
|
||||
echo " n = no "
|
||||
echo "--------------------------------"
|
||||
read choice3
|
||||
if [ "$choice3" == "y" ]; then
|
||||
echo "Selected the current user '$user'"
|
||||
loop2=1
|
||||
loop3=1
|
||||
follow
|
||||
elif [ "$choice3" == "n" ]; then # Corrected from 'no' to 'n'
|
||||
echo "Not selected the current user '$user'"
|
||||
loop3=1
|
||||
follow
|
||||
clear
|
||||
else
|
||||
echo "Pressed wrong button!"
|
||||
follow
|
||||
clear
|
||||
clear
|
||||
fi
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
#### NEEDED VARIABLES ####
|
||||
location="$(pwd)/../"
|
||||
home="/home/$user"
|
||||
bashrc="$home/.bashrc"
|
||||
mainfolder="$home/.bashrc.d/"
|
||||
neededfold="${mainfolder}scripts-needed"
|
||||
@@ -7,75 +103,34 @@ avfolder="${mainfolder}scripts-available"
|
||||
enfolder="${mainfolder}scripts-enabled"
|
||||
rmfolder="${mainfolder}scripts-removed"
|
||||
|
||||
## FUNCTIONS ##
|
||||
createdir(){
|
||||
if [ ! -d "$mainfolder" ]; then
|
||||
mkdir $mainfolder
|
||||
echo "[ Created $mainfolder ]"
|
||||
fi
|
||||
|
||||
if [ ! -d "$neededfold" ]; then
|
||||
mkdir $neededfold
|
||||
echo "[ Created $neededfold ]"
|
||||
fi
|
||||
|
||||
if [ ! -d "$avfolder" ]; then
|
||||
mkdir $avfolder
|
||||
echo "[ Created $avfolder ]"
|
||||
fi
|
||||
|
||||
if [ ! -d "$enfolder" ]; then
|
||||
mkdir $enfolder
|
||||
echo "[ Created $enfolder ]"
|
||||
fi
|
||||
|
||||
if [ ! -d "$rmfolder" ]; then
|
||||
mkdir $rmfolder
|
||||
echo "[ Created $rmfolder ]"
|
||||
fi
|
||||
}
|
||||
|
||||
modular-bashrc(){
|
||||
echo 'mkdir -p ~/.bashrc.d/scripts-needed' >> $bashrc
|
||||
echo 'mkdir -p ~/.bashrc.d/scripts-enabled' >> $bashrc
|
||||
echo 'mkdir -p ~/.bashrc.d/scripts-available' >> $bashrc
|
||||
echo 'if [ -d ~/.bashrc.d ]; then' >> $bashrc
|
||||
echo ' for needed in ~/.bashrc.d/scripts-needed/*.sh; do' >> $bashrc
|
||||
echo ' [ -r "$needed" ] && source "$needed"' >> $bashrc
|
||||
echo ' done' >> $bashrc
|
||||
echo ' unset needed' >> $bashrc
|
||||
echo ' for file in ~/.bashrc.d/scripts-enabled/*.sh; do' >> $bashrc
|
||||
echo ' [ -r "$file" ] && source "$file"' >> $bashrc
|
||||
echo ' done' >> $bashrc
|
||||
echo ' unset file' >> $bashrc
|
||||
echo 'fi' >> $bashrc
|
||||
}
|
||||
|
||||
copy-brc() {
|
||||
cp -r brc-script.sh ../scripts-needed/
|
||||
chmod 750 -R ../scripts-needed/brc-script.sh
|
||||
}
|
||||
|
||||
#### INSTALLATION ####
|
||||
cp "$bashrc" "bashrc-backup-`date +%F`"
|
||||
echo "[ Created a backup ]"
|
||||
cat NEEDED-FOR-INSTALLER >> $bashrc
|
||||
echo "[ Added info in the .bashrc file ]"
|
||||
cp -r $location $mainfolder
|
||||
echo "[ Installed Main Folder ]"
|
||||
echo $mainfolder
|
||||
source $bashrc
|
||||
echo "[ Refreshed bashrc ]"
|
||||
echo ""
|
||||
echo "Intallation Completed!"
|
||||
follow
|
||||
clear
|
||||
## EXECUTION ##
|
||||
echo "### Creation Folders ###"
|
||||
createdir
|
||||
echo "### Adding brc-script for .bashrc ###"
|
||||
modular-bashrc
|
||||
echo [ brc-script installed ]
|
||||
|
||||
echo "##################################"
|
||||
echo " Small Introduction "
|
||||
echo "##################################"
|
||||
echo ""
|
||||
echo "You can handle you script by adding in the $avfolder."
|
||||
echo "Make sure that all the the script that you are adding are added in a function, otherwise their will be loaded at each open of the bash cli."
|
||||
echo "You can start to handle all the script by writing the command brc-script, also you can refresh the bash with the command refresh-brc."
|
||||
echo "You can start to create your own script by use the 'brc-script -c' command"
|
||||
echo "To enable an available script (after you copied or created one in the scripts-available) by using 'brc-script -e' and the the index command that you need"
|
||||
echo "You can also modify the existing script by the 'brc-script -m' command."
|
||||
echo "You can handle your script by adding them in the $avfolder."
|
||||
echo "Make sure that all the scripts you add are within a function, otherwise they will be loaded each time you open the bash CLI."
|
||||
echo "You can start managing scripts by using the command 'brc-script', and refresh bash with 'refresh-brc'."
|
||||
echo "You can create your own script using 'brc-script -c'."
|
||||
echo "To enable an available script (after copying or creating one in the scripts-available), use 'brc-script -e' and provide the index."
|
||||
echo "You can also modify existing scripts using 'brc-script -m'."
|
||||
echo ""
|
||||
echo "##################################"
|
||||
echo " Thanks for using this script. "
|
||||
echo "##################################"
|
||||
echo " Visit my website www.simolinuxdesign.org to discover more plugin that i created!
|
||||
echo "Visit my website www.simolinuxdesign.org to discover more plugins I created!"
|
||||
|
||||
|
||||
@@ -1,338 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
###############
|
||||
### OPTIONS ###
|
||||
###############
|
||||
editor="vim"
|
||||
|
||||
#################
|
||||
### VARIABLES ###
|
||||
#################
|
||||
home_folder="$HOME/"
|
||||
available_scripts="${home_folder}.bashrc.d/scripts-available/"
|
||||
enabled_scripts="${home_folder}.bashrc.d/scripts-enabled/"
|
||||
needed_scripts="${home_folder}.bashrc.d/scripts-needed"
|
||||
bin_folder="${home_folder}.bashrc.d/scripts-removed/"
|
||||
bashrc="${home_folder}.bashrc"
|
||||
|
||||
#################
|
||||
### FUNCTIONS ###
|
||||
#################
|
||||
|
||||
# Refresh Bash #
|
||||
refresh-brc(){
|
||||
if [ "$1" == "-dis" ]; then
|
||||
echo "------------------------------------"
|
||||
echo "[ Bashrc Refreshed ]"
|
||||
echo "You can't use the old commands from now!"
|
||||
echo "------------------------------------"
|
||||
elif [ "$1" == "-en" ]; then
|
||||
echo "------------------------------------"
|
||||
echo "[ Bashrc Refreshed ]"
|
||||
echo "------------------------------------"
|
||||
echo "You can you the new commands from now!"
|
||||
echo "------------------------------------"
|
||||
else
|
||||
echo "[ Bashrc Refreshed ]"
|
||||
fi
|
||||
source "$bashrc"
|
||||
}
|
||||
|
||||
|
||||
createscript() {
|
||||
echo "------------------------------------"
|
||||
echo " Creation New Scripts: "
|
||||
echo "------------------------------------"
|
||||
echo "Name of the script: "
|
||||
read namenewscript
|
||||
if [ -f "${available_scripts}$namenewscript" ]; then
|
||||
echo "Script already exists!"
|
||||
else
|
||||
newscriptav="${available_scripts}$namenewscript.sh"
|
||||
|
||||
### INITIALIZZATION NEW SCRIPT ###
|
||||
touch $newscriptav
|
||||
echo "#!/bin/bash" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "### OPTIONS ###" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "### VARIABLES ###" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "### FUNCTIONS ###" >> $newscriptav
|
||||
echo "${namenewscript}() {" >> $newscriptav
|
||||
echo "# Add your code here!" >> $newscriptav
|
||||
echo 'echo "This is the new script"' >> $newscriptav
|
||||
echo "}" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "### EXECUTE ###" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
### END NEW SCRIPT ###
|
||||
|
||||
vim "$newscriptav"
|
||||
echo "------------------------------------"
|
||||
echo " Script $namenewscript created!"
|
||||
echo " Do you want to enable it?"
|
||||
echo "------------------------------------"
|
||||
echo " 1 | yes "
|
||||
echo " 2 | no "
|
||||
echo " Def | no "
|
||||
echo "------------------------------------"
|
||||
read answer
|
||||
if [ "$answer" -eq 1 ]; then
|
||||
ln -sf "$newscriptav" "${enabled_scripts}$namenewscript.sh"
|
||||
refresh-brc -en
|
||||
else
|
||||
echo "Script not enabled!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
listitem() {
|
||||
index=0
|
||||
for i in $(ls "$available_scripts"); do
|
||||
inotext=${i:0:-3}
|
||||
(( index ++ ))
|
||||
if [ -f "$enabled_scripts$i" ]; then
|
||||
echo "$index) - $inotext"
|
||||
else
|
||||
echo "$index) $inotext"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
managescript() {
|
||||
echo "------------------------------------"
|
||||
echo " Select the index: "
|
||||
echo "------------------------------------"
|
||||
read manageindex
|
||||
index2=1
|
||||
for i in $(ls "$available_scripts"); do
|
||||
if [ "$manageindex" == "$index2" ]; then
|
||||
# DISABLE WITH NUMBER #
|
||||
if [ "$1" == "--disable" ]; then
|
||||
if [ ! -f "${enabled_scripts}$i" ]; then
|
||||
echo "Script not enabled!"
|
||||
else
|
||||
unlink "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "[ Scripts $inoext Disabled ]"
|
||||
refresh-brc -dis
|
||||
fi
|
||||
# ENABLE WITH NUMBER #
|
||||
elif [ "$1" == "--enable" ]; then
|
||||
if [ -f "${enabled_scripts}$i" ]; then
|
||||
echo "Script already enabled!"
|
||||
else
|
||||
ln -sf "$available_scripts$i" "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "------------------------------------"
|
||||
echo "[ Scripts $inoext Enabled ]"
|
||||
refresh-brc -en
|
||||
fi
|
||||
|
||||
# MODIFY WITH NUMBER #
|
||||
elif [ "$1" == "--modify" ]; then
|
||||
if [ "$editor" == "vim" ]; then
|
||||
vim "$available_scripts$i"
|
||||
elif [ "$editor" == "nano" ]; then
|
||||
nano "$available_scripts$i"
|
||||
else
|
||||
echo "------------"
|
||||
echo " 1 - nano "
|
||||
echo " 2 - vim "
|
||||
echo " def - vim "
|
||||
echo "------------"
|
||||
read ched
|
||||
if [ "$ched" == "1" ]; then
|
||||
nano "$available_scripts$i"
|
||||
else
|
||||
vim "$available_scripts$i"
|
||||
fi
|
||||
fi
|
||||
clear
|
||||
echo "------------------------------------"
|
||||
echo "Would you like to rename the script?"
|
||||
echo "------------------------------------"
|
||||
echo " 1 | yes "
|
||||
echo " 2 | no "
|
||||
echo " default | no "
|
||||
echo "------------------------------------"
|
||||
read renscr
|
||||
if [ $renscr == "1" ]; then
|
||||
clear
|
||||
countloop=0
|
||||
while [ $countloop -lt 1 ]; do
|
||||
echo "------------------------------------"
|
||||
echo "Insert new name:"
|
||||
read renamenow
|
||||
echo "------------------------------------"
|
||||
echo "Is the name correct? "
|
||||
echo "------------------------------------"
|
||||
echo " 1 | no "
|
||||
echo " 0 | yes "
|
||||
echo " default | yes "
|
||||
echo "------------------------------------"
|
||||
read confirm
|
||||
if [ "$confirm" == "1" ]; then
|
||||
countloop=0
|
||||
clear
|
||||
echo "------------------------------------"
|
||||
echo "Rename again the file:"
|
||||
else
|
||||
wasenabled=0
|
||||
if [ -f "$enabled_scripts$i" ]; then
|
||||
unlink "$enabled_scripts$i"
|
||||
echo "[ Temporary Disabled Script ]"
|
||||
wasenabled=1
|
||||
fi
|
||||
mv "$available_scripts$i" "${available_scripts}$renamenow.sh"
|
||||
echo "[ Script $i renamed to $renamenow.sh ]"
|
||||
if [ "$wasenabled" -eq 1 ]; then
|
||||
ln -sf "${available_scripts}$renamenow.sh" "${enabled_scripts}$renamenow.sh"
|
||||
echo "[ Script Enabled Again ]"
|
||||
fi
|
||||
countloop=1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
refresh-brc -en
|
||||
# REMOVE SCRIPT #
|
||||
elif [ "$1" == "--remove" ]; then
|
||||
if [ ! -d "$bin_folder" ]; then
|
||||
mkdir $bin_folder
|
||||
fi
|
||||
if [ -f "${enabled_scripts}$i" ]; then
|
||||
unlink "${enabled_scripts}$i"
|
||||
echo "[ Script $i unabled! ]"
|
||||
fi
|
||||
removed_data="$i-`date +%F`_`date +%T`"
|
||||
mv "${available_scripts}$i" "${bin_folder}$removed_data"
|
||||
echo "[ Script $i removed! ] "
|
||||
echo "You can find it in the folder: "
|
||||
echo "'$bin_folder' "
|
||||
echo "------------------------------------"
|
||||
refresh-brc
|
||||
fi
|
||||
|
||||
break
|
||||
fi
|
||||
((index2++))
|
||||
done
|
||||
}
|
||||
|
||||
removescript(){
|
||||
echo "------------------------------------"
|
||||
echo " Remove Script "
|
||||
echo "------------------------------------"
|
||||
listitem
|
||||
managescript --remove
|
||||
}
|
||||
|
||||
enablescript() {
|
||||
echo "------------------------------------"
|
||||
echo " Enable Scripts "
|
||||
echo "------------------------------------"
|
||||
listitem
|
||||
managescript --enable
|
||||
}
|
||||
|
||||
enableallscript() {
|
||||
for i in $(ls "$available_scripts"); do
|
||||
ln -sf "$available_scripts$i" "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "enabled $inoext"
|
||||
done
|
||||
echo "------------------------------------"
|
||||
echo "[ All available scripts enabled ]"
|
||||
refresh-brc -en
|
||||
}
|
||||
|
||||
|
||||
disablescript() {
|
||||
echo "------------------------------------"
|
||||
echo " Disable Scripts "
|
||||
echo "------------------------------------"
|
||||
listitem
|
||||
managescript --disable
|
||||
}
|
||||
|
||||
|
||||
disableallscript() {
|
||||
# Disabilita tutti gli script
|
||||
for i in $(ls "$enabled_scripts"); do
|
||||
unlink "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "disabled $inoext"
|
||||
done
|
||||
echo "------------------------------------"
|
||||
echo "[ All Scripts Disabled ]"
|
||||
refresh-brc -dis
|
||||
}
|
||||
|
||||
#################
|
||||
### EXECUTION ###
|
||||
#################
|
||||
|
||||
# Main Script #
|
||||
brc-script() {
|
||||
### ENABLE SCRIPTS ###
|
||||
if [ "$1" == "-e" ]; then
|
||||
enablescript
|
||||
|
||||
### ENABLE ALL SCRIPTS ###
|
||||
elif [ "$1" == "-ea" ]; then
|
||||
enableallscript
|
||||
|
||||
### DISABLE SCRIPT ###
|
||||
elif [ "$1" == "-d" ]; then
|
||||
disablescript
|
||||
|
||||
### DISABLE ALL SCRIPTS ###
|
||||
elif [ "$1" == "-da" ]; then
|
||||
disableallscript
|
||||
|
||||
### SCRIPTS LIST ###
|
||||
elif [ "$1" == "-l" ]; then
|
||||
echo "------------------------------------"
|
||||
echo " Scripts List "
|
||||
echo "------------------------------------"
|
||||
listitem
|
||||
echo "------------------------------------"
|
||||
echo " The script preceded by the"
|
||||
echo " '-' character is active. "
|
||||
echo "------------------------------------"
|
||||
|
||||
### MODIFY SCRIPTS ###
|
||||
elif [ "$1" == "-m" ]; then
|
||||
echo "###### MODIFY SCRIPTS #######"
|
||||
listitem
|
||||
managescript --modify
|
||||
|
||||
### CREATE NEW SCRIPT ###
|
||||
elif [ "$1" == "-c" ]; then
|
||||
createscript
|
||||
|
||||
### REMOVE SCRIPT ###
|
||||
elif [ "$1" == "-r" ]; then
|
||||
removescript
|
||||
|
||||
### COMMAND LISTS ###
|
||||
else
|
||||
echo "-----------------------------"
|
||||
echo " List of brc-scripts command "
|
||||
echo "-----------------------------"
|
||||
echo " -c | Create New Script "
|
||||
echo " -m | Modify Script "
|
||||
echo " -l | Scripts List "
|
||||
echo " -e | Enable Scripts "
|
||||
echo " -d | Disable Scripts "
|
||||
echo " -da | Disable All Scripts "
|
||||
echo " -ea | Enable All Scripts "
|
||||
echo " -r | Remove Script "
|
||||
echo "-----------------------------"
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user