Make scripts more POSIX-y

This commit is contained in:
Andrew Scott 2024-02-19 20:49:12 -05:00
parent 426f13f7ba
commit c2e542bab4
Signed by: a
GPG key ID: 7CD5A5977E4931C1
6 changed files with 55 additions and 51 deletions

View file

@ -1,27 +1,28 @@
#!/bin/bash
#!/bin/sh
START_TIME=`date +"%b %d, %Y %T"`
LOG_FILE_WIRE="${XDG_STATE_HOME}"/wireplumber.log
LOG_FILE_PIPE="${XDG_STATE_HOME}"/pipewire.log
LOG_FILE_PULSE="${XDG_STATE_HOME}"/pipewire-pulse.log
user=$(id -u)
time=$(date +"%b %d, %Y %T")
wire_log=$XDG_STATE_HOME/wireplumber.log
pipe_log=$XDG_STATE_HOME/pipewire.log
pulse_log=$XDG_STATE_HOME/pipewire-pulse.log
echo "--- ${START_TIME} ---" > "$LOG_FILE_WIRE"
echo "--- ${START_TIME} ---" > "$LOG_FILE_PIPE"
echo "--- ${START_TIME} ---" > "$LOG_FILE_PULSE"
echo "--- $time ---" > "$wire_log"
echo "--- $time ---" > "$pipe_log"
echo "--- $time ---" > "$pulse_log"
# Kill any running pipewire processes
killall -q wireplumber & killall -q pipewire-pulse & killall -q pipewire
# Wait for processes to stop
while pgrep -u $UID -x wireplumber >/dev/null; do sleep 1; done
while pgrep -u $UID -x pipewire >/dev/null; do sleep 1; done
while pgrep -u $UID -x pipewire-pulse >/dev/null; do sleep 1; done
while pgrep -u "$user" -x wireplumber >/dev/null; do sleep 1; done
while pgrep -u "$user" -x pipewire >/dev/null; do sleep 1; done
while pgrep -u "$user" -x pipewire-pulse >/dev/null; do sleep 1; done
# Wait for xdg-desktop-portal to start
until pgrep -u $UID -f /usr/lib/xdg-desktop-portal >/dev/null; do sleep 1; done
until pgrep -u "$user" -f /usr/lib/xdg-desktop-portal >/dev/null; do sleep 1; done
# Launch pipewire
/usr/bin/wireplumber 2>&1 | tee -a "$LOG_FILE_WIRE" & disown
/usr/bin/pipewire 2>&1 | tee -a "$LOG_FILE_PIPE" & disown
/usr/bin/pipewire-pulse 2>&1 | tee -a "$LOG_FILE_PULSE" & disown
/usr/bin/wireplumber 2>&1 | tee -a "$wire_log" &
/usr/bin/pipewire 2>&1 | tee -a "$pipe_log" &
/usr/bin/pipewire-pulse 2>&1 | tee -a "$pulse_log" &

View file

@ -1,5 +0,0 @@
#!/bin/bash
RIVER=`ps -C river | awk '/river/'`
[[ $RIVER != "" ]] && riverctl spawn 'reset' && riverctl exit || echo "River is not running."

View file

@ -1,9 +1,9 @@
#!/bin/bash
#!/bin/sh
START_TIME=`date +"%b %d, %Y %T"`
LOG_FILE="${XDG_STATE_HOME}"/swayidle.log
time=$(date +"%b %d, %Y %T")
log_file=$XDG_STATE_HOME/swayidle.log
echo "--- ${START_TIME} ---" > "$LOG_FILE"
echo "--- $time ---" > "$log_file"
# kill running processes
killall -q swayidle
@ -21,19 +21,19 @@ swayidle -w \
resume 'wlr-randr --output eDP-1 --on && kanshictl reload' \
lock 'waylock-launcher' \
before-sleep 'waylock-launcher' \
2>&1 | tee -a "$LOG_FILE" & disown
2>&1 | tee -a "$log_file" &
{{- else if eq .chezmoi.hostname "hydrus" }}
# lock: 5m, display: 15m
swayidle -w \
timeout 300 'waylock-launcher' \
timeout 900 'wlr-randr --output DP-1 --off --output DP-2 --off' \
resume 'wlr-randr --output DP-1 --on --output DP-2 --on && sleep 2 && kanshictl reload' \
timeout 900 'kanshictl switch dual-off' \
resume 'kanshictl switch dual' \
lock 'waylock-launcher' \
before-sleep 'waylock-launcher' \
2>&1 | tee -a "$LOG_FILE" & disown
2>&1 | tee -a "$log_file" &
{{- else }}
# lock after 5m
swayidle -w \
timeout 300 'waylock-launcher' \
2>&1 | tee -a "$LOG_FILE" & disown
2>&1 | tee -a "$log_file" &
{{ end }}

View file

@ -1,19 +1,20 @@
#!/bin/bash
#!/bin/sh
START_TIME=`date +"%b %d, %Y %T"`
LOG_FILE="${XDG_STATE_HOME}"/waybar.log
user=$(id -u)
time=$(date +"%b %d, %Y %T")
log_file=$XDG_STATE_HOME/waybar.log
echo "--- ${START_TIME} ---" > "$LOG_FILE"
echo "--- $time ---" > "$log_file"
# Terminate already running bar instances
killall -q waybar
# Wait until the processes have been shut down
while pgrep -u $UID -x waybar >/dev/null; do sleep 1; done
while pgrep -u "$user" -x waybar >/dev/null; do sleep 1; done
# Make sure pipewire-pulse is running or module won't load
until pgrep -u $UID -x pipewire-pulse >/dev/null; do sleep 1; done
until pgrep -u "$user" -x pipewire-pulse >/dev/null; do sleep 1; done
# Launch Waybar
waybar 2>&1 | tee -a "$LOG_FILE" & disown
waybar 2>&1 | tee -a "$log_file" &

View file

@ -1,10 +1,13 @@
#!/bin/bash
#!/bin/sh
START_TIME=`date +"%b %d, %Y %T"`
LOG_FILE="${XDG_STATE_HOME}"/waylock.log
echo "--- ${START_TIME} ---" > "$LOG_FILE"
user=$(id -u)
time=$(date +"%b %d, %Y %T")
log_file=$XDG_STATE_HOME/waylock.log
if pgrep -u $UID -x waylock >/dev/null; then
echo "--- $time ---" > "$log_file"
if pgrep -u "$user" -x waylock >/dev/null; then
echo "error: waylock is already running" >> "$log_file"
exit 1
else
waylock \
@ -12,6 +15,6 @@ else
-init-color 0x000000 \
-fail-color 0x000000 \
-input-color 0x525c62 \
2>&1 | tee -a "$LOG_FILE" & disown
2>&1 | tee -a "$log_file"
fi

View file

@ -1,21 +1,25 @@
#!/bin/bash
#!/bin/sh
START_TIME=`date +"%b %d, %Y %T"`
LOG_FILE_BAR1="${XDG_STATE_HOME}"/yambar1.log
echo "--- ${START_TIME} ---" > "$LOG_FILE_BAR1"
user=$(id -u)
time=$(date +"%b %d, %Y %T")
bar1_log=$XDG_STATE_HOME/yambar1.log
{{- if eq .chezmoi.hostname "hydrus" }}
LOG_FILE_BAR2="${XDG_STATE_HOME}"/yambar2.log
echo "--- ${START_TIME} ---" > "$LOG_FILE_BAR2"
bar2_log=$XDG_STATE_HOME/yambar2.log
{{- end }}
echo "--- $time ---" > "$bar1_log"
{{- if eq .chezmoi.hostname "hydrus" }}
echo "--- $time ---" > "$bar2_log"
{{- end }}
# Terminate already running bar instances
killall -q yambar
# Wait until the processes have been shut down
while pgrep -u $UID -x yambar >/dev/null; do sleep 1; done
while pgrep -u "$user" -x yambar >/dev/null; do sleep 1; done
# Launch Yambar
yambar -s 2>&1 | tee -a "$LOG_FILE_BAR1" & disown
yambar -s 2>&1 | tee -a "$bar1_log" &
{{- if eq .chezmoi.hostname "hydrus" }}
yambar -s -c "${XDG_CONFIG_HOME}/yambar/bar2.yml" 2>&1 | tee -a "$LOG_FILE_BAR2" & disown
yambar -s -c "$XDG_CONFIG_HOME/yambar/bar2.yml" 2>&1 | tee -a "$bar2_log" &
{{- end }}