#!/bin/bash

opt=$1

if [ "x$opt" == "x--install" ]; then
  xfconf-query -n -c xfce4-power-manager -p /xfce4-panel/command-logout -t string -s "xlinux-logout"
  xfconf-query -n -c xfce4-power-manager -p /xfce4-panel/command-profile -t string -s "xlinux-user-pw-change"
  # xfce4-session-logout ersetzen
  sed -i 's/^.*value="actions"/z4\
z4.1\
z4.2\
z4.3/g' t

  exit 0
fi


a=0
a=$(($a + $(pgrep -u root -c -x "xlinux-update")))
a=$(($a + $(pgrep -u root -c -x "apt")))
a=$(($a + $(pgrep -u root -c -x "apt-get")))
a=$(($a + $(pgrep -u root -c -x "dpkg")))
if [ $a -gt 0 ]; then
  echo "Es läuft bereits ein Update-Prozess, oder die Datei /var/lib/dpkg/lock ist gesperrt."
  zenity --error --title="Abbruch" --width=400 --text="Abschalten ist aktuell gesperrt, weil aktuell Updates installiert werden oder eine Softwareeinrichtung läuft.\n\nBitte versuchen Sie es später nochmal." &
  exit 1
else
  xfce4-session-logout "$1" "$2" "$3" &
fi

exit 0
