2019-10-21 18:20:09 +00:00
|
|
|
#!/bin/bash
|
2019-10-23 14:28:41 +00:00
|
|
|
# Copyright 2019 Archie Hilton <archie.hilton1@gmail.com>
|
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2019-10-24 16:34:14 +00:00
|
|
|
VERSION="0.2"
|
2019-10-21 18:20:09 +00:00
|
|
|
|
2019-11-06 14:53:58 +00:00
|
|
|
DEFAULT_CONFIG_DIR="/usr/share/dwmbar"
|
2019-11-06 14:50:04 +00:00
|
|
|
export DEFAULT_CONFIG_DIR
|
2019-11-06 14:52:31 +00:00
|
|
|
DEFAULT_MODULES_DIR="$DEFAULT_CONFIG_DIR/modules/"
|
2019-11-06 14:50:04 +00:00
|
|
|
export DEFAULT_MODULES_DIR
|
2019-10-24 16:27:20 +00:00
|
|
|
DEFAULT_BAR_LOCATION="$DEFAULT_CONFIG_DIR/bar.sh"
|
2019-11-06 14:50:04 +00:00
|
|
|
export DEFAULT_BAR_LOCATION
|
2019-10-24 14:31:03 +00:00
|
|
|
DEFAULT_CONFIG_LOCATION="$DEFAULT_CONFIG_DIR/config"
|
2019-11-06 14:50:04 +00:00
|
|
|
export DEFAULT_CONFIG_LOCATION
|
2019-10-23 14:14:27 +00:00
|
|
|
|
2019-11-06 14:52:31 +00:00
|
|
|
CONFIG_DIR="/home/$USER/.config/dwmbar/"
|
2019-11-06 14:50:04 +00:00
|
|
|
export CONFIG_DIR
|
|
|
|
|
2019-11-06 14:52:31 +00:00
|
|
|
CUSTOM_DIR="$CONFIG_DIR/custom/"
|
2019-11-06 14:50:04 +00:00
|
|
|
export CUSTOM_DIR
|
|
|
|
|
2019-10-24 14:31:03 +00:00
|
|
|
CONFIG_FILE="$CONFIG_DIR/config"
|
2019-11-06 14:50:04 +00:00
|
|
|
if [[ ! -f "$CONFIG_FILE" ]]; then
|
|
|
|
CONFIG_FILE=$DEFAULT_CONFIG_LOCATION
|
|
|
|
fi
|
|
|
|
export CONFIG_FILE
|
|
|
|
|
2019-11-06 14:37:29 +00:00
|
|
|
CACHE_DIR="$HOME/.cache/dwmbar/"
|
|
|
|
export CACHE_DIR
|
2019-10-21 18:20:09 +00:00
|
|
|
|
2019-11-04 09:21:40 +00:00
|
|
|
INTERNET=1
|
2019-11-01 18:21:46 +00:00
|
|
|
export INTERNET
|
|
|
|
|
2019-10-21 18:20:09 +00:00
|
|
|
print_help(){
|
2019-10-23 14:04:02 +00:00
|
|
|
echo "dwmbar $VERSION
|
|
|
|
-v Display this help message.
|
|
|
|
-c Copy default files to /home/$USER/.config/dwmbar
|
|
|
|
"
|
2019-10-22 22:02:57 +00:00
|
|
|
}
|
2019-10-21 18:20:09 +00:00
|
|
|
|
2019-10-23 14:04:02 +00:00
|
|
|
copy_usr_to_home(){
|
2019-10-22 22:02:57 +00:00
|
|
|
[[ ! -d $CONFIG_DIR ]] && cp -r /usr/share/dwmbar $CONFIG_DIR
|
2019-10-24 14:31:03 +00:00
|
|
|
[[ ! -f $CONFIG_FILE ]] && cp /usr/share/dwmbar/config $CONFIG_FILE
|
2019-10-22 22:02:57 +00:00
|
|
|
[[ ! -d $CUSTOM_DIR ]] && mkdir $CUSTOM_DIR
|
2019-10-21 18:20:09 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 14:14:27 +00:00
|
|
|
check_files(){
|
2019-11-06 14:37:29 +00:00
|
|
|
if [[ ! -d "$DEFAULT_CONFIG_DIR" ]]; then
|
2019-10-23 14:14:27 +00:00
|
|
|
echo "$DEFAULT_CONFIG_DIR does not exist." > /dev/stderr
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-11-06 14:37:29 +00:00
|
|
|
if [[ ! -d "$DEFAULT_MODULES_DIR" ]]; then
|
2019-10-23 14:14:27 +00:00
|
|
|
echo "$DEFAULT_MODULES_DIR does not exist." > /dev/stderr
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-11-06 14:37:29 +00:00
|
|
|
if [[ ! -d "$CACHE_DIR" ]]; then
|
|
|
|
mkdir -p "$CACHE_DIR"
|
|
|
|
fi
|
2019-11-06 14:08:45 +00:00
|
|
|
|
2019-11-06 14:37:29 +00:00
|
|
|
if [[ ! -f "$DEFAULT_BAR_LOCATION" ]]; then
|
2019-10-24 16:27:20 +00:00
|
|
|
echo "$DEFAULT_BAR_LOCATION does not exist." > /dev/stderr
|
2019-10-23 14:14:27 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2019-10-24 14:31:03 +00:00
|
|
|
|
2019-11-06 14:37:29 +00:00
|
|
|
if [[ ! -f "$DEFAULT_CONFIG_LOCATION" ]]; then
|
2019-10-24 14:31:03 +00:00
|
|
|
echo "$DEFAULT_CONFIG_LOCATION does not exist." > /dev/stderr
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-10-23 14:14:27 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 14:31:03 +00:00
|
|
|
while getopts 'vc' flag; do
|
2019-10-23 14:04:02 +00:00
|
|
|
case "${flag}" in
|
|
|
|
v) print_help
|
|
|
|
exit 0 ;;
|
|
|
|
c) copy_usr_to_home
|
|
|
|
exit 0 ;;
|
|
|
|
esac
|
|
|
|
done
|
2019-10-22 22:02:57 +00:00
|
|
|
|
2019-10-23 14:14:27 +00:00
|
|
|
check_files
|
|
|
|
|
2019-10-21 19:15:51 +00:00
|
|
|
while :; do
|
2019-11-01 18:21:46 +00:00
|
|
|
date=$(date +'%S')
|
|
|
|
if [ $(( 10#$date % 5 )) -eq 0 ]; then
|
|
|
|
wget --spider -q www.google.com
|
|
|
|
|
|
|
|
if [[ $? -eq 0 ]]; then
|
|
|
|
INTERNET=0
|
|
|
|
else
|
|
|
|
INTERNET=1
|
|
|
|
fi
|
|
|
|
fi
|
2019-11-01 18:36:07 +00:00
|
|
|
xsetroot -name "$(exec $DEFAULT_BAR_LOCATION)"
|
2019-10-21 19:15:51 +00:00
|
|
|
done
|