diff --git a/scripts/app_close_and_restart.sh b/scripts/app_close_and_restart.sh new file mode 100755 index 0000000..d428b3c --- /dev/null +++ b/scripts/app_close_and_restart.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# Funktion til Flatpak apps +close_flatpak() { + local app="$1" + flatpak kill "$app" + for i in $(seq 1 5); do + sleep 1 + if ! pgrep -f "$app" > /dev/null; then + echo "$app closed (attempt $i)" + return + fi + echo "$app still running, retrying ($i/5)..." + flatpak kill "$app" + done + echo "$app force closing (KILL)..." + pkill -KILL -f "$app" + pkill -KILL -f bwrap 2>/dev/null # dræb sandbox container +} +# Funktion til native apps +close_app() { + local app="$1" + pkill -TERM -f "$app" + for i in $(seq 1 5); do + sleep 1 + if ! pgrep -f "$app" > /dev/null; then + echo "$app closed (attempt $i)" + return + fi + echo "$app still running, retrying ($i/5)..." + pkill -TERM -f "$app" + done + echo "$app force closing (KILL)..." + pkill -KILL -f "$app" +} +# Luk apps +close_flatpak "com.discordapp.Discord" +close_flatpak "io.github.lullabyX.sone" +close_flatpak "rocks.shy.VacuumTube" +close_app "firefox" +# Steam +if pgrep -f steam > /dev/null; then + steam -shutdown + for i in $(seq 1 5); do + sleep 1 + if ! pgrep -f steam > /dev/null; then + echo "Steam closed (attempt $i)" + break + fi + echo "Steam still running ($i/5)..." + done + pkill -KILL -f steam 2>/dev/null +else + echo "Steam not running, skipping..." +fi +# Popup +zenity --question \ + --title="Restart" \ + --text="All programs have been closed.\nDo you want to restart the PC?" \ + --ok-label="Restart" \ + --cancel-label="Cancel" \ + 2>/dev/null +if [ $? -eq 0 ]; then + sudo shutdown -r now +fi diff --git a/scripts/app_close_and_shutdown.sh b/scripts/app_close_and_shutdown.sh new file mode 100755 index 0000000..51a835f --- /dev/null +++ b/scripts/app_close_and_shutdown.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +# Funktion til Flatpak apps +close_flatpak() { + local app="$1" + flatpak kill "$app" + for i in $(seq 1 5); do + sleep 1 + if ! pgrep -f "$app" > /dev/null; then + echo "$app closed (attempt $i)" + return + fi + echo "$app still running, retrying ($i/5)..." + flatpak kill "$app" + done + echo "$app force closing (KILL)..." + pkill -KILL -f "$app" + pkill -KILL -f bwrap 2>/dev/null # dræb sandbox container +} + +# Funktion til native apps +close_app() { + local app="$1" + pkill -TERM -f "$app" + for i in $(seq 1 5); do + sleep 1 + if ! pgrep -f "$app" > /dev/null; then + echo "$app closed (attempt $i)" + return + fi + echo "$app still running, retrying ($i/5)..." + pkill -TERM -f "$app" + done + echo "$app force closing (KILL)..." + pkill -KILL -f "$app" +} + +# Luk apps +close_flatpak "com.discordapp.Discord" +close_flatpak "io.github.lullabyX.sone" +close_flatpak "rocks.shy.VacuumTube" +close_app "firefox" + +# Steam +if pgrep -f steam > /dev/null; then + steam -shutdown + for i in $(seq 1 5); do + sleep 1 + if ! pgrep -f steam > /dev/null; then + echo "Steam closed (attempt $i)" + break + fi + echo "Steam still running ($i/5)..." + done + pkill -KILL -f steam 2>/dev/null +else + echo "Steam not running, skipping..." +fi + +# Popup +zenity --question \ + --title="Shutdown" \ + --text="All programs have been closed.\nDo you want to shut down the PC?" \ + --ok-label="Shut down" \ + --cancel-label="Cancel" \ + 2>/dev/null + +if [ $? -eq 0 ]; then + sudo shutdown -h now +fi