brendotools-wallman/wpset

129 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
# setting USER variable
USER=$(logname)
# WPDL
VERSION=""
CONF="/home/$USER/.config/wpdl.conf"
source $CONF
source /etc/wpdl/parse
# updater
if [ "$1" = "-u" ]; then
# root check
ROOT=$(whoami)
if [ "$ROOT" != "root" ]; then
echo "ERR_ROOT_PRIVS_REQUIRE"
echo "(try re-running this script with sudo.)"
exit
fi
# contact tildegit to check for a new release
parse
# compare versions
WPSET_REMOTEVER=$(echo "$DOWNLOAD_VERSION")
WPSET_LOCALVER=$(wpset -v)
if [ "$WPSET_REMOTEVER" == "$WPSET_LOCALVER" ]; then
# tell user that there's nothing to do
echo "you are already running the latest available version of wallman."
exit
else
# download the update
cd /home/$USER/
FOLDER_CHECK=$(ls | grep brendotools-wallman)
if [ "$FOLDER_CHECK" != "" ]; then
rm -rf brendotools-wallman*
fi
git clone https://tildegit.org/BrendanTCC/brendotools-wallman/
cd brendotools-wallman
git checkout tags/$DOWNLOAD_VERSION
# set the version because GOOD GOD I'M A LAZY CUNT
echo wpset | sed "s/VERSION\=\"\"/VERSION\=\"$DOWNLOAD_VERSION\""
# install the update
mv wpset /bin/wpset
chmod +x /bin/wpset
mv parse /etc/wpdl/parse
chmod +x /etc/wpdl/parse
cd /home/$USER/
rm -rf brendotools-wallman/
echo "done."
WPSET_LOCALVER=$(wpset -v)
if [ "$WPSET_LOCALVER" == "$WPSET_REMOTEVER" ]; then
echo "success! wpset version updated to $WPSET_LOCALVER."
else
echo "something's gone wrong. wpset version is '$WPSET_LOCALVER' when it should be $WPSET_REMOTEVER.\
try manually moving the file and running wpset -v."
fi
fi
# version
if [ "$1" = "-v" ]; then
echo "$VERSION"
exit
fi
# set last wp
if [ "$1" = "last" ]; then
feh --bg-max $WALL_LOC/$LAST
exit
fi
function wplist() {
curl -u $SSH_USER: sftp://$SSH_HOST/home/$SSH_USER/wp.list
}
function listupdate() {
echo "updating wallpaper list..."
ssh $SSH_USER@$SSH_HOST "bash /home/$SSH_USER/bin/wplist" &> /dev/null
}
listupdate
if [ -z "$1" ]; then
echo "usage: wpset <wallpaper name>"
echo "to list available wallpapers: wpset -l"
echo "[for startup script] to set last wp: wpset last"
exit
fi
# wallpaper list
if [ "$1" = "-l" ]; then
wplist
exit
fi
if [ "$1" = "list" ]; then
wplist
exit
fi
# check for locally installed walls and set em if it's there
WPCHECK=$(ls $WALL_LOC | grep $1)
if [ "$WPCHECK" = "$1" ]; then
feh --bg-max $WALL_LOC/$1
echo "$1" > $WALL_LOC/.lastwp
exit
else
# wallpaper lookup
WPLIST=$(wplist | grep $1)
if [ "$WPLIST" = "$1" ]; then
# download the actual script
curl -s sftp://$SSH_HOST/home/$SSH_USER/bin/wpdl -u $SSH_USER: -o wpdl
chmod +x wpdl
clear
$PWD/wpdl $*
rm wpdl
[ -e wp.list ] && rm $PWD/wp.list
else
clear
echo "could not find the wallpaper you requested, here's a list of what's available:"
wplist
fi
fi
fi