Browse Source

kernel.sh: Add error helper function

master
Riyyi 3 years ago
parent
commit
9e9e017aa9
  1. 24
      kernel.sh

24
kernel.sh

@ -16,9 +16,14 @@ blue="$(tput setf 1)"
red="$(tput setf 4)" red="$(tput setf 4)"
n="$(tput sgr0)" n="$(tput sgr0)"
if [ "$(dirname "$0")" != "." ]; then error()
echo "${b}${red}Error:${n} please run this script from the directory it resides." >&2 {
echo "${b}${red}Error:${n} $1" >&2
exit 1 exit 1
}
if [ "$(dirname "$0")" != "." ]; then
error "please run this script from the directory it resides."
fi fi
help() help()
@ -48,16 +53,14 @@ EOF
cdSafe() cdSafe()
{ {
if ! cd "$1" 2> /dev/null; then if ! cd "$1" 2> /dev/null; then
echo "${b}${red}Error:${n} no such file or directory: $1" >&2 error "no such file or directory: $1"
exit 1
fi fi
} }
fileExist() fileExist()
{ {
if [ ! -f "$1" ] ; then if [ ! -f "$1" ] ; then
echo "${b}${red}Error:${n} no such file or directory: $1" >&2 error "no such file or directory: $1"
exit 1
fi fi
} }
@ -71,8 +74,7 @@ checkDependencies()
for dependency in $dependencies; do for dependency in $dependencies; do
if ! pacman -Qs "$dependency" > /dev/null; then if ! pacman -Qs "$dependency" > /dev/null; then
echo "${b}${red}Error:${n} required dependency '$dependency' is missing." >&2 error "required dependency '$dependency' is missing."
exit 1
fi fi
done done
} }
@ -112,13 +114,11 @@ install()
found="$(echo "$packages" | wc -l)" found="$(echo "$packages" | wc -l)"
if [ "$found" -ne 2 ]; then if [ "$found" -ne 2 ]; then
echo "${b}${red}Error:${n} kernel was not build yet." >&2 error "kernel was not build yet."
exit 1
fi fi
if ! sudo -v; then if ! sudo -v; then
echo "${b}${red}Error:${n} you cannot perform this operation uness you are root." >&2 error "you cannot perform this operation uness you are root."
exit 1
fi fi
echo "$packages" | xargs --open-tty sudo pacman -U --needed echo "$packages" | xargs --open-tty sudo pacman -U --needed

Loading…
Cancel
Save