Added better error checking in install and dwmbar

This commit is contained in:
Archie Hilton (thytom) 2019-10-23 15:14:27 +01:00
parent 9e41bf1bc6
commit 77a41faeac
2 changed files with 26 additions and 2 deletions

23
dwmbar
View file

@ -1,6 +1,10 @@
#!/bin/bash #!/bin/bash
VERSION="0.1" VERSION="0.1"
DEFAULT_CONFIG_DIR="/usr/share/dwmbar"
DEFAULT_MODULES_DIR="$DEFAULT_CONFIG_DIR/modules"
DEFAULT_RC_LOCATION="$DEFAULT_CONFIG_DIR/dwmbarrc"
RC_LOCATION="/home/$USER/.config/dwmbar/dwmbarrc" RC_LOCATION="/home/$USER/.config/dwmbar/dwmbarrc"
CONFIG_DIR="/home/$USER/.config/dwmbar" CONFIG_DIR="/home/$USER/.config/dwmbar"
MODULES_DIR="$CONFIG_DIR/modules" MODULES_DIR="$CONFIG_DIR/modules"
@ -23,6 +27,23 @@ copy_usr_to_home(){
[[ ! -d $CACHE_DIR ]] && mkdir $CACHE_DIR [[ ! -d $CACHE_DIR ]] && mkdir $CACHE_DIR
} }
check_files(){
if [[ ! -d $DEFAULT_CONFIG_DIR ]]; then
echo "$DEFAULT_CONFIG_DIR does not exist." > /dev/stderr
exit 1
fi
if [[ ! -d $DEFAULT_MODULES_DIR ]]; then
echo "$DEFAULT_MODULES_DIR does not exist." > /dev/stderr
exit 1
fi
if [[ ! -f $DEFAULT_RC_LOCATION ]]; then
echo "$DEFAULT_RC_LOCATION does not exist." > /dev/stderr
exit 1
fi
}
while getopts 'v' flag; do while getopts 'v' flag; do
case "${flag}" in case "${flag}" in
v) print_help v) print_help
@ -32,6 +53,8 @@ while getopts 'v' flag; do
esac esac
done done
check_files
while :; do while :; do
xsetroot -name "$(exec $RC_LOCATION)" xsetroot -name "$(exec $RC_LOCATION)"
done done

View file

@ -3,12 +3,13 @@
DWMBAR="/usr/bin/dwmbar" DWMBAR="/usr/bin/dwmbar"
if [ "$EUID" -ne 0 ] if [ "$EUID" -ne 0 ]
then echo "Please run as root" then echo "Please run as root" > /dev/stderr
exit 1 exit 1
fi fi
if [[ ! -f "dwmbar" ]]; then if [[ ! -f "dwmbar" ]]; then
echo "dwmbar executable not found." echo "dwmbar executable not found." > /dev/stderr
exit 1
fi fi
# Create /usr/share/dwmbar # Create /usr/share/dwmbar