Add sh library

This commit is contained in:
Santiago Lo Coco 2021-12-26 19:23:38 -03:00
parent 18c188cad7
commit edd59e814b
2 changed files with 56 additions and 30 deletions

View File

@ -24,11 +24,11 @@ checkParameters() {
;; ;;
w) w)
checkForDependencies "libnewt" checkForDependencies "libnewt"
displayDialog=useWhiptail setDialogBox "whiptail"
;; ;;
d) d)
checkForDependencies "dialog" checkForDependencies "dialog"
displayDialog=useDialog setDialogBox "dialog"
;; ;;
?) ?)
printf '%s: invalid option - '\''%s'\'\\n "${0##*/}" "$OPTARG" printf '%s: invalid option - '\''%s'\'\\n "${0##*/}" "$OPTARG"
@ -39,27 +39,27 @@ checkParameters() {
if [ $counter -eq 0 ]; then if [ $counter -eq 0 ]; then
checkForDependencies "libnewt" checkForDependencies "libnewt"
displayDialog=useWhiptail setDialogBox "whiptail"
fi fi
} }
getGitconfigData() { getGitconfigData() {
$displayDialog --yesno "Would you like to set up gitconfig?" displayDialogBox --yesno "Would you like to set up gitconfig?"
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
return return
fi fi
$displayDialog --msgbox "Now, I will ask you for data to set up gitconfig personal account." displayDialogBox --msgbox "Now, I will ask you for data to set up gitconfig personal account."
gitPersonalName=$($displayDialog --inputbox "Enter a name." 3>&1 1>&2 2>&3) gitPersonalName=$(displayDialogBox --inputbox "Enter a name." 3>&1 1>&2 2>&3)
gitPersonalMail=$($displayDialog --inputbox "Enter an e-mail." 3>&1 1>&2 2>&3) gitPersonalMail=$(displayDialogBox --inputbox "Enter an e-mail." 3>&1 1>&2 2>&3)
$displayDialog --msgbox "Let's continue with the work account." displayDialogBox --msgbox "Let's continue with the work account."
gitWorkPath=$($displayDialog --inputbox "Enter an absolute folder path where you would like to use the work account." 3>&1 1>&2 2>&3) gitWorkPath=$(displayDialogBox --inputbox "Enter an absolute folder path where you would like to use the work account." 3>&1 1>&2 2>&3)
while [[ ! -d $gitWorkPath ]]; do while [[ ! -d $gitWorkPath ]]; do
gitWorkPath=$($displayDialog --no-cancel --inputbox "Path isn't valid. Please try again" 3>&1 1>&2 2>&3) gitWorkPath=$(displayDialogBox --no-cancel --inputbox "Path isn't valid. Please try again" 3>&1 1>&2 2>&3)
done done
gitWorkName=$($displayDialog --inputbox "Enter a name." 3>&1 1>&2 2>&3) gitWorkName=$(displayDialogBox --inputbox "Enter a name." 3>&1 1>&2 2>&3)
gitWorkMail=$($displayDialog --inputbox "Enter an e-mail." 3>&1 1>&2 2>&3) gitWorkMail=$(displayDialogBox --inputbox "Enter an e-mail." 3>&1 1>&2 2>&3)
sed -e "s/PERSONAL_NAME/$gitPersonalName/g" -e "s/PERSONAL_MAIL/$gitPersonalMail/g" -e "s|WORK_PATH|${gitWorkPath}|g" ./templates/.gitconfig > ./dotfiles/.gitconfig sed -e "s/PERSONAL_NAME/$gitPersonalName/g" -e "s/PERSONAL_MAIL/$gitPersonalMail/g" -e "s|WORK_PATH|${gitWorkPath}|g" ./templates/.gitconfig > ./dotfiles/.gitconfig
sed -e "s/WORK_NAME/$gitWorkName/g" -e "s/WORK_MAIL/$gitWorkMail/g" ./templates/.gitconfig-work > ./dotfiles/.gitconfig-work sed -e "s/WORK_NAME/$gitWorkName/g" -e "s/WORK_MAIL/$gitWorkMail/g" ./templates/.gitconfig-work > ./dotfiles/.gitconfig-work
@ -90,30 +90,28 @@ checkForDependencies() {
fi fi
} }
useDialog() {
dialog "$@" 9 60
}
useWhiptail() {
whiptail "$@" 0 0
}
startRice() { startRice() {
displayDialogBox --title "CocoRice" --msgbox "Hi! This script will auto install my dotfiles."
getGitconfigData
# sh scripts/linkFiles.sh
sh scripts/install.sh
displayDialogBox --title "CocoRice" --msgbox "All done! Enjoy..."
}
runScript() {
lastFolder=$(pwd -P) lastFolder=$(pwd -P)
cocoRiceFolder=$(echo "$(pwd -P)" | awk '{ sub(/CocoRice.*/, "CocoRice"); print }') cocoRiceFolder=$(echo "$(pwd -P)" | awk '{ sub(/CocoRice.*/, "CocoRice"); print }')
cd $cocoRiceFolder cd $cocoRiceFolder
$displayDialog --title "CocoRice" --msgbox "Hi! This script will auto install my dotfiles." source scripts/common.sh
getGitconfigData checkParameters $@
sh scripts/linkFiles.sh checkForDependencies
sh scripts/install.sh
$displayDialog --title "CocoRice" --msgbox "All done! Enjoy..."
clear startRice
# clear
cd $lastFolder cd $lastFolder
} }
checkParameters $@ runScript $@
checkForDependencies
startRice

28
scripts/common.sh Normal file
View File

@ -0,0 +1,28 @@
#!/bin/sh
displayDialogBox() {
case $dialogBox in
whiptail)
useWhiptail "$@"
;;
dialog)
useDialog "$@"
;;
?)
echo "Unknown dialogBox variable" >&2
exit 1
;;
esac
}
useDialog() {
dialog "$@" 9 60
}
useWhiptail() {
whiptail "$@" 0 0
}
setDialogBox() {
export dialogBox=${1}
}