commit 9c23e94bd2ec468974b39cf8a4dfc419043340c5 Author: BrendanTCC Date: Sat Aug 21 11:56:26 2021 +1000 initial commit diff --git a/wpdl b/wpdl new file mode 100644 index 0000000..1a4efc4 --- /dev/null +++ b/wpdl @@ -0,0 +1,112 @@ +#!/bin/bash +CONF="/home/$USER/.config/wpdl.conf" +source $CONF +WPFILE="$1" +SMBGET=$(command -v smbget) +FEH=$(command -v feh) +LASTWP=$(cat $WALL_LOC/.lastwp) +WPSET_REMOTEVER=$(curl sftp://$HOST_DISP/home/$SSH_USER/bin/wpset -u $SSH_USER: | grep VERSION | sed "s/\# VERSION //") +WPSET_LOCALVER=$(cat /bin/wpset | grep VERSION | sed "s/\# VERSION //") + +if [ "$WPSET_REMOTEVER" != "$WPSET_LOCALVER" ]; then +curl sftp://$SSH_HOST/home/$SSH_USER/bin/wpset-update -u $SSH_USER: | bash +fi + +# function for setting our wallpaper +function setwall() { + echo "setting $WPFILE as system wallpaper..." + feh --bg-max $WALL_LOC/$WPFILE + echo "$WPFILE" > $WALL_LOC/.lastwp + echo "done!" + exit +} + +# dependency installer +function depinstall() { +if [ "$DEPREQ" = "true" ]; then +PASSWD=$(pass system/sudo) +echo $PASSWD | sudo -S apt install $DEPS -y +fi +} + +# is zenity configured to be a floater? +echo "check to see if zenity is in floating mode" +ZENFREE=$(cat /home/$USER/.config/i3/config | grep "zenfree=true") +if [ "$ZENFREE" = "# zenfree=true" ]; then +# if yes... +echo "she's free!" +else +# if not... +echo "window not floating, adding to config" +echo "# zenfree=true" | tee -a /home/$USER/.config/i3/config &> /dev/null +echo "for_window [class=\"Zenity\" instance=\"zenity\"] floating enable" | tee -a /home/$USER/.config/i3/config &> /dev/null +i3-msg restart &> /dev/null +fi + + +SMBUSR=$(zenity --forms --text "Enter your credentials for the remote server '$HOST_DISP'" --add-entry "Username" --add-password "Password" --title "WallpaperDL") + +# depcheck: wpset +WPSET=$(command -v wpset) +if [ "$WPSET" = "/bin/wpset" ]; then +echo "" +else +PASSWD=$(pass system/sudo) +curl -s sftp://$SSH_HOST/home/$SSH_USER/bin/wpset -u $SSH_USER: -o wpset +echo '$PASSWD' | sudo -S mv wpset /bin/wpset +echo '$PASSWD' | sudo -S chmod +x /bin/wpset +echo "we noticed you don't have wpset installed. as it's now a dependency, it's been installed for you." +fi + +# depcheck: SMBGet +echo "check for smbget" +if [ "$SMBGET" = "/usr/bin/smbget" ]; then +echo "smbget is installed, continuing..." +else +echo "smbget is missing, downloading and installing..." +DEPS="$DEPS smbclient" +DEPREQ="true" +fi + +# dependency check: feh +echo "check for feh" +if [ "$FEH" = "/usr/bin/feh" ]; then +echo "feh is installed, continuing..." +else +echo "feh is missing, adding to installer" +DEPS="$DEPS feh" +DEPREQ="true" +fi + +depinstall + +# parse username and password +SMBUSER=$(echo "$SMBUSR" | awk -F'|' '{print $1}') +SMBPASS=$(echo "$SMBUSR" | awk -F'|' '{print $2}') + +# debugging things +# echo "username: $SMBUSER" +# echo "password: $SMBPASS" + +# download wallpaper if not already downloaded +#echo 'clearing wallpaper folder...' +#rm -rf "$WALL_LOC/" +#sleep 2 +echo "downloading file..." +mkdir -p "$WALL_LOC/" +cd "$WALL_LOC/" + +echo "[create ssh tunnel]" +ssh -f -N -M -S $WALL_LOC/ssh-sock -L 1445:$HOST:445 $SSH_USER@$HOST_DISP +echo "[wait 5s for it to establish]" +sleep 5 +echo "[pull file from Samba share]" +smbget -v smb://$SMBUSER:$SMBPASS@$HOST:1445/$SMBFOLDER/$WPFILE + +setwall + +echo "[kill ssh tunnel]" +ssh -S $WALL_LOC/ssh-sock -O exit $SSH_USER@$HOST_DISP +sleep 2 +rm $WALL_LOC/ssh-sock +echo "exiting..." diff --git a/wplist b/wplist new file mode 100755 index 0000000..1ac43cf --- /dev/null +++ b/wplist @@ -0,0 +1,5 @@ +#!/bin/bash +# collates a list of wallpapers available on a samba share. + +ls /home/brendo/Wallpapers > ../wp.list +echo "list collated, cleaning up and closing" diff --git a/wpset b/wpset new file mode 100755 index 0000000..40692dd --- /dev/null +++ b/wpset @@ -0,0 +1,79 @@ +#!/bin/bash +# WPDL +VERSION="0.1-rev80" +CONF="/home/$USER/.config/wpdl.conf" +source $CONF + +# updater +if [ "$1" = "-u" ]; then +curl sftp://$HOST_DISP/home/$SSH_USER/bin/wpset-update -u $SSH_USER: | bash +exit +fi + +# version +if [ "$1" = "-v" ]; then +echo "v$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/sysadmin/bin/wplist" &> /dev/null +} + +listupdate + +if [ -z "$1" ]; then +echo "usage: wpset " +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://brendo.org/home/sysadmin/bin/wpdl -u sysadmin: -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 diff --git a/wpset-update b/wpset-update new file mode 100644 index 0000000..629f379 --- /dev/null +++ b/wpset-update @@ -0,0 +1,22 @@ +#!/bin/bash +CONF="/home/$USER/.config/wpdl.conf" +source $CONF +WPSET_REMOTEVER=$(curl sftp://$SSH_HOST/home/$SSH_USER/bin/wpset -u $SSH_USER: | grep -m1 VERSION | sed "s/VERSION\=//g" | sed s/\"//g) +WPSET_LOCALVER=$(wpset -v) +clear + +if [ "$WPSET_REMOTEVER" == "$WPSET_LOCALVER" ]; then + +echo "no updates to install, latest version already installed" +exit + +else +PASSWD=$(pass system/sudo) +curl sftp://$SSH_HOST/home/$SSH_USER/bin/wpset -o wpset -u $SSH_USER: +echo "$PASSWD" | sudo -S mv wpset /bin/wpset +echo "$PASSWD" | sudo -S chmod +x /bin/wpset +sleep 1 +echo "wpset updated." +WPSET_LOCALVER=$(wpset -v) +echo "wpset version is now $WPSET_LOCALVER." +fi