Run shellcheck (loc 138-601)

This commit is contained in:
Santiago Lo Coco 2022-01-12 18:44:59 -03:00
parent fe2d89b6bd
commit 42d8277278
1 changed files with 41 additions and 41 deletions

View File

@ -138,21 +138,21 @@ getSize() {
} }
createSwapfile() { createSwapfile() {
dd if=/dev/zero of=$swapfile bs=1M count=${size} status=progress 2>&1 | debug dd if=/dev/zero of=$swapfile bs=1M count="${size}" status=progress 2>&1 | debug
chmod 600 $swapfile 2>&1 | debug chmod 600 $swapfile 2>&1 | debug
mkswap $swapfile 2>&1 | debug mkswap $swapfile 2>&1 | debug
swapon $swapfile 2>&1 | debug swapon $swapfile 2>&1 | debug
} }
autoPart() { autoPart() {
parted -s $disk mklabel gpt 2>&1 | debug parted -s "$disk" mklabel gpt 2>&1 | debug
sgdisk $disk -n=1:0:+300M -t=1:ef00 2>&1 | debug sgdisk "$disk" -n=1:0:+300M -t=1:ef00 2>&1 | debug
if [ -n "$swapPart" ]; then if [ -n "$swapPart" ]; then
sgdisk $disk -n=2:0:+${size}M -t=2:8200 2>&1 | debug sgdisk "$disk" -n=2:0:+"${size}"M -t=2:8200 2>&1 | debug
sgdisk $disk -n=3:0:0 2>&1 | debug sgdisk "$disk" -n=3:0:0 2>&1 | debug
else else
sgdisk $disk -n=2:0:0 2>&1 | debug sgdisk "$disk" -n=2:0:0 2>&1 | debug
fi fi
} }
@ -168,17 +168,17 @@ mountPart() {
if [ $autoSelection = false ]; then if [ $autoSelection = false ]; then
result=$(whiptail --title "Select where to mount boot partition." --menu "" 0 0 0 "/boot/efi" "" "/boot" "" "==OTHER==" "" 3>&1 1>&2 2>&3) result=$(whiptail --title "Select where to mount boot partition." --menu "" 0 0 0 "/boot/efi" "" "/boot" "" "==OTHER==" "" 3>&1 1>&2 2>&3)
exitIfCancel "You must select a path." exitIfCancel "You must select a path."
bootPath=$(echo $result | sed 's/^\///g') bootPath=$(echo "$result" | sed 's/^\///g')
if [ "$result" = "OTHER" ]; then if [ "$result" = "OTHER" ]; then
local IFS=' ' local IFS=' '
result=$(whiptail --inputbox "Enter the absolute path." 0 0 3>&1 1>&2 2>&3) result=$(whiptail --inputbox "Enter the absolute path." 0 0 3>&1 1>&2 2>&3)
exitIfCancel "You must enter a path." exitIfCancel "You must enter a path."
bootPath=$(echo $result | sed 's/^\///g') bootPath=$(echo "$result" | sed 's/^\///g')
mkdir -p "/mnt/$bootPath" mkdir -p "/mnt/$bootPath"
while [[ ! -d "/mnt/$bootPath" ]]; do while [[ ! -d "/mnt/$bootPath" ]]; do
result=$(whiptail --inputbox "Path isn't valid. Please try again" 0 0 3>&1 1>&2 2>&3) result=$(whiptail --inputbox "Path isn't valid. Please try again" 0 0 3>&1 1>&2 2>&3)
exitIfCancel "You must enter a path." exitIfCancel "You must enter a path."
bootPath=$(echo $result | sed 's/^\///g') bootPath=$(echo "$result" | sed 's/^\///g')
mkdir -p "/mnt/$bootPath" mkdir -p "/mnt/$bootPath"
done done
else else
@ -197,11 +197,11 @@ mountPart() {
} }
debug() { debug() {
if [ $debugFlagToStdout = true ]; then if [ "$debugFlagToStdout" = true ]; then
tee tee
elif [ $debugFlagToFile = true ]; then elif [ "$debugFlagToFile" = true ]; then
tee -a CocoASAIS.log > /dev/null tee -a CocoASAIS.log > /dev/null
elif [ $debugFlag = true ]; then elif [ "$debugFlag" = true ]; then
tee -a CocoASAIS.log tee -a CocoASAIS.log
else else
tee > /dev/null tee > /dev/null
@ -212,10 +212,10 @@ installPackage() {
calcWidthAndRun "whiptail --infobox \"Installing '$1'.\" 7 WIDTH" calcWidthAndRun "whiptail --infobox \"Installing '$1'.\" 7 WIDTH"
case ${3} in case ${3} in
A) A)
if [ $debugFlagToStdout = true ] || [ $debugFlag = true ]; then if [ "$debugFlagToStdout" = true ] || [ "$debugFlag" = true ]; then
script -qec "pacstrap /mnt --needed ${1}" /dev/null 2>&1 | debug script -qec "pacstrap /mnt --needed ${1}" /dev/null 2>&1 | debug
else else
pacstrap /mnt --needed ${1} 2>&1 | debug pacstrap /mnt --needed "${1}" 2>&1 | debug
fi fi
;; ;;
B) B)
@ -225,7 +225,7 @@ installPackage() {
[ $? -eq 0 ] && return [ $? -eq 0 ] && return
flag="--needed" flag="--needed"
fi fi
if [ $debugFlagToStdout = true ] || [ $debugFlag = true ]; then if [ "$debugFlagToStdout" = true ] || [ "$debugFlag" = true ]; then
runInChroot "script -qec \"pacman -S $flag --noconfirm ${1}\" /dev/null" 2>&1 | debug runInChroot "script -qec \"pacman -S $flag --noconfirm ${1}\" /dev/null" 2>&1 | debug
else else
runInChroot "pacman -S $flag --noconfirm ${1}" 2>&1 | debug runInChroot "pacman -S $flag --noconfirm ${1}" 2>&1 | debug
@ -238,14 +238,14 @@ installPackage() {
[ $? -eq 0 ] && return [ $? -eq 0 ] && return
flag="--needed" flag="--needed"
fi fi
if [ $debugFlagToStdout = true ] || [ $debugFlag = true ]; then if [ "$debugFlagToStdout" = true ] || [ "$debugFlag" = true ]; then
runInChroot "script -qec \"sudo -u $username paru -S $flag --noconfirm --skipreview ${1}\" /dev/null" 2>&1 | debug runInChroot "script -qec \"sudo -u $username paru -S $flag --noconfirm --skipreview ${1}\" /dev/null" 2>&1 | debug
else else
runInChroot "sudo -u $username paru -S $flag --noconfirm --skipreview ${1}" 2>&1 | debug runInChroot "sudo -u $username paru -S $flag --noconfirm --skipreview ${1}" 2>&1 | debug
fi fi
;; ;;
D) D)
pkgName=$(echo ${1} | grep -oP '(?<=/).*?(?=.git)') pkgName=$(echo "${1}" | grep -oP '(?<=/).*?(?=.git)')
runInChroot "sudo -u $username paru -Q ${pkgName}" 2>&1 | debug runInChroot "sudo -u $username paru -Q ${pkgName}" 2>&1 | debug
[ $? -eq 0 ] && return [ $? -eq 0 ] && return
runInChroot "cd /tmp; sudo -u $username git clone https://github.com/${1}; cd ${pkgName}; sudo -u $username makepkg -si --noconfirm; cd ..; rm -rf ${pkgName}" 2>&1 | debug runInChroot "cd /tmp; sudo -u $username git clone https://github.com/${1}; cd ${pkgName}; sudo -u $username makepkg -si --noconfirm; cd ..; rm -rf ${pkgName}" 2>&1 | debug
@ -299,11 +299,11 @@ setTimeZone() {
formatOptions $(ls -l /usr/share/zoneinfo/ | grep '^d' | awk '{printf $9" \n"}' | awk '!/posix/ && !/right/') formatOptions $(ls -l /usr/share/zoneinfo/ | grep '^d' | awk '{printf $9" \n"}' | awk '!/posix/ && !/right/')
region=$(whiptail --title "Region" --menu "" 0 0 0 "${options[@]}" 3>&1 1>&2 2>&3) region=$(whiptail --title "Region" --menu "" 0 0 0 "${options[@]}" 3>&1 1>&2 2>&3)
exitIfCancel "You must select a region." exitIfCancel "You must select a region."
formatOptions $(ls -l /usr/share/zoneinfo/${region} | grep -v '^d' | awk '{printf $9" \n"}') formatOptions $(ls -l "/usr/share/zoneinfo/${region}" | grep -v '^d' | awk '{printf $9" \n"}')
city=$(whiptail --title "City" --menu "" 0 0 0 "${options[@]}" 3>&1 1>&2 2>&3) city=$(whiptail --title "City" --menu "" 0 0 0 "${options[@]}" 3>&1 1>&2 2>&3)
exitIfCancel "You must select a city." exitIfCancel "You must select a city."
ln -sf /mnt/usr/share/zoneinfo/${region}/${city} /mnt/etc/localtime ln -sf "/mnt/usr/share/zoneinfo/${region}/${city}" /mnt/etc/localtime
printWaitBox printWaitBox
runInChroot "hwclock --systohc" runInChroot "hwclock --systohc"
} }
@ -333,9 +333,9 @@ calcWidthAndRun() {
if [[ $comm != *"3>&1 1>&2 2>&3" ]]; then if [[ $comm != *"3>&1 1>&2 2>&3" ]]; then
comm="${comm} 3>&1 1>&2 2>&3" comm="${comm} 3>&1 1>&2 2>&3"
fi fi
commOutput=$(eval $comm) commOutput=$(eval "$comm")
exitStatus=$? exitStatus=$?
[ -n $commOutput ] && echo $commOutput [ -n "$commOutput" ] && echo "$commOutput"
return $exitStatus return $exitStatus
} }
@ -351,9 +351,9 @@ calcHeightAndRun() {
if [[ $comm != *"3>&1 1>&2 2>&3" ]]; then if [[ $comm != *"3>&1 1>&2 2>&3" ]]; then
comm="${comm} 3>&1 1>&2 2>&3" comm="${comm} 3>&1 1>&2 2>&3"
fi fi
commOutput=$(eval $comm) commOutput=$(eval "$comm")
exitStatus=$? exitStatus=$?
[ -n $commOutput ] && echo $commOutput [ -n "$commOutput" ] && echo "$commOutput"
return $exitStatus return $exitStatus
} }
@ -386,8 +386,8 @@ updateMirrors() {
curl -o /etc/pacman.d/mirrorlist.pacnew https://archlinux.org/mirrorlist/all/ 2>&1 | debug curl -o /etc/pacman.d/mirrorlist.pacnew https://archlinux.org/mirrorlist/all/ 2>&1 | debug
local IFS=$'\n' local IFS=$'\n'
setDelimiters "" "OFF" setDelimiters "" "OFF"
formatOptions $(cat /etc/pacman.d/mirrorlist.pacnew | grep '^##' | cut -d' ' -f2- | sed -n '5~1p') formatOptions $(grep '^##' /etc/pacman.d/mirrorlist.pacnew | cut -d' ' -f2- | sed -n '5~1p')
countries=$(whiptail --title "Countries" --checklist "" 0 0 0 "${options[@]}" 3>&1 1>&2 2>&3) countries=$(whiptail --title "Countries" --checklist "" 25 40 19 "${options[@]}" 3>&1 1>&2 2>&3)
[ -z "$countries" ] && printAndExit "You must select at least one country." [ -z "$countries" ] && printAndExit "You must select at least one country."
countriesFmt=$(echo "$countries" | sed -r 's/" "/,/g') countriesFmt=$(echo "$countries" | sed -r 's/" "/,/g')
printWaitBox printWaitBox
@ -414,12 +414,12 @@ saveVar() {
loadVar() { loadVar() {
var=$(grep "$1=" CocoASAIS.vars | cut -d= -f2) var=$(grep "$1=" CocoASAIS.vars | cut -d= -f2)
export $1=$var export "$1"="$var"
} }
tryLoadVar() { tryLoadVar() {
loadVar $1 loadVar "$1"
if [ -z ${!1} ]; then if [ -z "${!1}" ]; then
calcWidthAndRun "whiptail --msgbox \"Couldn't load '$1'. Try to run the script again.\" 7 WIDTH" calcWidthAndRun "whiptail --msgbox \"Couldn't load '$1'. Try to run the script again.\" 7 WIDTH"
rm -f CocoASAIS.vars rm -f CocoASAIS.vars
exit 1 exit 1
@ -456,7 +456,7 @@ checkSudoers() {
installOtherPackages() { installOtherPackages() {
calcHeightAndRun "whiptail --msgbox \"Now, we will install a few more packages (in the background). Press OK and wait (it may take some time).\" HEIGHT 60 3>&1 1>&2 2>&3" calcHeightAndRun "whiptail --msgbox \"Now, we will install a few more packages (in the background). Press OK and wait (it may take some time).\" HEIGHT 60 3>&1 1>&2 2>&3"
[ -z $username ] && tryLoadVar "username" [ -z "$username" ] && tryLoadVar "username"
getThePackages "S" "installOtherPackages" getThePackages "S" "installOtherPackages"
checkForParu checkForParu
getThePackages "N" "installOtherPackages" getThePackages "N" "installOtherPackages"
@ -481,45 +481,45 @@ finishInstallation() {
getDotfiles() { getDotfiles() {
zshConfig zshConfig
local lastFolder=$(pwd -P) local lastFolder=$(pwd -P)
cd $HOME/Documents cd "$HOME/Documents" || printAndExit "Couldn't cd into $HOME/Documents"
git clone https://github.com/santilococo/CocoRice.git 2>&1 | debug git clone https://github.com/santilococo/CocoRice.git 2>&1 | debug
cd CocoRice cd CocoRice || printAndExit "Couldn't cd into ./CocoRice"
sh scripts/bootstrap.sh -w sh scripts/bootstrap.sh -w
cd $lastFolder cd "$lastFolder" || printAndExit "Couldn't cd into $lastFolder"
sudo rm -f ~/.bashrc /usr/bin/CocoASAIS sudo rm -f ~/.bashrc /usr/bin/CocoASAIS
mkdir -p $HOME/.cache/zsh mkdir -p "$HOME/.cache/zsh"
touch $HOME/.cache/zsh/.histfile touch "$HOME/.cache/zsh/.histfile"
chsh -s $(which zsh) chsh -s "$(which zsh)"
} }
checkForSystemdUnit() { checkForSystemdUnit() {
trap 'systemctl stop ${2}; forceExit=true' INT trap 'systemctl stop ${2}; forceExit=true' INT
if [ "${3}" = "oneshot" ]; then if [ "${3}" = "oneshot" ]; then
[ "$(systemctl show -p ActiveState --value ${2})" = "inactive" ] && return [ "$(systemctl show -p ActiveState --value "${2}")" = "inactive" ] && return
else else
systemctl is-active --quiet ${2} && return systemctl is-active --quiet "${2}" && return
fi fi
forceExit=false forceExit=false
calcWidthAndRun "whiptail --infobox \"Waiting for the ${1} to finish. Please wait.\" 7 WIDTH" calcWidthAndRun "whiptail --infobox \"Waiting for the ${1} to finish. Please wait.\" 7 WIDTH"
if [ "${3}" = "oneshot" ]; then if [ "${3}" = "oneshot" ]; then
while [ $forceExit = false ]; do while [ $forceExit = false ]; do
result=$(systemctl show -p ActiveState --value ${2}) result=$(systemctl show -p ActiveState --value "${2}")
[ "$result" = "inactive" ] && break [ "$result" = "inactive" ] && break
sleep 1 sleep 1
done done
else else
systemctl is-active --quiet ${2} systemctl is-active --quiet "${2}"
while [ $? -ne 0 ] && [ $forceExit = false ]; do while [ $? -ne 0 ] && [ $forceExit = false ]; do
sleep 1 sleep 1
systemctl is-active --quiet ${2} systemctl is-active --quiet "${2}"
done done
fi fi
trap - INT trap - INT
} }
printStepIfDebug() { printStepIfDebug() {
if [ $debugFlagToFile = true ] || [ $debugFlag = true ]; then if [ "$debugFlagToFile" = true ] || [ "$debugFlag" = true ]; then
printf '\n%s' "============================================================" >> CocoASAIS.log printf '\n%s' "============================================================" >> CocoASAIS.log
printf '\n%s\n' "$step" >> CocoASAIS.log printf '\n%s\n' "$step" >> CocoASAIS.log
printf '%s\n' "============================================================" >> CocoASAIS.log printf '%s\n' "============================================================" >> CocoASAIS.log