brendotools-wallman/wpdl

113 lines
3.1 KiB
Bash

#!/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..."