From b9bc23d46ea9e4f9635fbac34dacdc447fd43a1f Mon Sep 17 00:00:00 2001 From: the_4n0nym0u53 Date: Sat, 8 Jan 2022 16:24:17 +0100 Subject: [PATCH] Shell scripts: - Improve install script with for loop - Change hash bangs to /bin/sh because I've symlinked /bin/sh to dash, they should work with bash as well due to POSIX compliance --- install.sh | 37 ++++++++++++------------- scripts/.local/bin/clear-clipboard.sh | 2 +- scripts/.local/bin/update.sh | 8 ++++++ scripts/.local/bin/vfio.sh | 2 +- waybar/.config/waybar/ivpn-reconnect.sh | 2 +- waybar/.config/waybar/ivpn-status.sh | 4 +-- 6 files changed, 30 insertions(+), 25 deletions(-) create mode 100755 scripts/.local/bin/update.sh diff --git a/install.sh b/install.sh index ce2592e..d9c47f2 100755 --- a/install.sh +++ b/install.sh @@ -1,31 +1,28 @@ #!/bin/sh -echo -e "Configuring directories..." -DOTDIR=$(cd -- "$(dirname -- $0)" &> /dev/null && pwd) +echo "Configuring directories..." +cd -- "$(dirname -- $0)" ZDOTDIR="$HOME/.config/zsh" -mkdir -p $ZDOTDIR # Symlink only the individual files instead of the entire directory +mkdir -p "$ZDOTDIR" # Symlink only the individual files instead of the entire directory sleep 0.5 -echo -e "Creating the symlinks with stow..." +echo "Creating the symlinks with stow..." -stow -d $DOTDIR -t $HOME --ignore="README.md" alacritty \ - mako \ - nvim \ - scripts \ - sway \ - swaylock \ - swaynag \ - waybar \ - zsh +for dir in * +do + [ -d "$dir" ] && stow -t "$HOME" --ignore="README.md" "$dir" +done sleep 0.5 -echo -e "Making scripts executable..." +echo "Making scripts executable..." -chmod +x $DOTDIR/scripts/.local/bin/clear-clipboard.sh -chmod +x $DOTDIR/sway/.config/sway/autostart.sh -chmod +x $DOTDIR/waybar/.config/waybar/ivpn-status.sh -chmod +x $DOTDIR/waybar/.config/waybar/ivpn-reconnect.sh -chmod +x $DOTDIR/waybar/.config/waybar/mediaplayer.py +chmod +x scripts/.local/bin/clear-clipboard.sh +chmod +x scripts/.local/bin/update.sh +chmod +x scripts/.local/bin/vfio.sh +chmod +x sway/.config/sway/autostart.sh +chmod +x waybar/.config/waybar/ivpn-reconnect.sh +chmod +x waybar/.config/waybar/ivpn-status.sh +chmod +x waybar/.config/waybar/mediaplayer.py sleep 0.5 -echo -e "Done!" +echo "Done!" diff --git a/scripts/.local/bin/clear-clipboard.sh b/scripts/.local/bin/clear-clipboard.sh index 80d13ac..ff78998 100755 --- a/scripts/.local/bin/clear-clipboard.sh +++ b/scripts/.local/bin/clear-clipboard.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env dash +#!/bin/sh wl-copy -c wl-copy -pc diff --git a/scripts/.local/bin/update.sh b/scripts/.local/bin/update.sh new file mode 100755 index 0000000..24c4c0a --- /dev/null +++ b/scripts/.local/bin/update.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +[ "$(lsb_release -si)" = "Artix" ] && paru +[ "$(lsb_release -si)" = "Fedora" ] && sudo dnf upgrade + +command -v flatpak >/dev/null 2>&1 && { echo; flatpak update; } +command -v npm >/dev/null 2>&1 && { echo; npm up -g; } +command -v docker >/dev/null 2>&1 && { echo; docker images | awk '(NR>1) && ($2!~/none/) {print $1":"$2}' | xargs -l docker pull; } diff --git a/scripts/.local/bin/vfio.sh b/scripts/.local/bin/vfio.sh index 7866059..6bc2789 100755 --- a/scripts/.local/bin/vfio.sh +++ b/scripts/.local/bin/vfio.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env dash +#!/bin/sh if [ $(id -u) -ne 0 ]; then echo "This script must be run as root. Quitting..." diff --git a/waybar/.config/waybar/ivpn-reconnect.sh b/waybar/.config/waybar/ivpn-reconnect.sh index 6a0fb9d..f6b0ce6 100755 --- a/waybar/.config/waybar/ivpn-reconnect.sh +++ b/waybar/.config/waybar/ivpn-reconnect.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env dash +#!/bin/sh if ivpn connect -last; then notify-send -u low "IVPN" "Successfully reconnected to IVPN server:\n$(ivpn status | sed -n 2p | xargs)" diff --git a/waybar/.config/waybar/ivpn-status.sh b/waybar/.config/waybar/ivpn-status.sh index e361721..d35233f 100755 --- a/waybar/.config/waybar/ivpn-status.sh +++ b/waybar/.config/waybar/ivpn-status.sh @@ -1,6 +1,6 @@ -#!/usr/bin/env dash +#!/bin/sh -STATUS=`ivpn status | awk '{print "\\\n"$0}' | head -n -1` +STATUS=`ivpn status | awk '{print "\\\n"$0}'` TOOLTIP=`env echo -E ${STATUS} | cut -c 3-` CLASS=`env echo ${STATUS} | grep 'VPN' | awk '{print $3}' | tr [:upper:] [:lower:]`