s243a

/usr/bin/wmexit

Apr 9th, 2019
139
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. script=${0##*/}
  4. script2=$1
  5.  
  6. case $script in wmexit|wmreboot|wmpoweroff|restartwm) OK=1 ;; esac
  7. case $script2 in wmexit|wmreboot|wmpoweroff|restartwm) script=$script2 ; OK=1 ;; esac
  8. [ ! "$OK" ] && echo "ERROR: $script is not valid" && exit 1
  9.  
  10. echo $script
  11.  
  12. case $script in
  13.  
  14.   restartwm)
  15.     #Exit from window manager will cause return to xwin, which reads
  16.     #/tmp/wmexitmode.txt and will relaunch w.m.
  17.     NEXTWM="$1"
  18.     PREVIOUSWM="`cat /etc/windowmanager`"
  19.     [ "$NEXTWM" = "" ] && NEXTWM="$PREVIOUSWM" #v1.0.7 precaution.
  20.     echo -n "$NEXTWM" > /etc/windowmanager #this makes change permanent.
  21.     #/sbin/pup_event_frontend_d will quit if this file exists...
  22.     echo -n "$NEXTWM" > /tmp/wmexitmode.txt
  23.     chmod 777 /tmp/wmexitmode.txt
  24.     ;;
  25.  
  26.   wmexit)
  27.     #Exit from X, will cause return to xwin.
  28.     #/sbin/pup_event_frontend_d will quit if this file exists...
  29.     echo -n "exit" > /tmp/wmexitmode.txt
  30.     chmod 777 /tmp/wmexitmode.txt
  31.     ;;
  32.   wmlogout)
  33.     echo -n "logout" > /tmp/wmexitmode.txt
  34.     chmod 777 /tmp/wmexitmode.txt
  35.     ;;  
  36.   wmreboot|wmpoweroff)
  37.     #introduced v0.9.8
  38.     #called from /root/.fvwm95rc, .jwmrc at shutdown.
  39.     #110918 call new script 'shutdownconfig'.
  40.     #120216 offer to set default language in initrd.
  41.     #130221 return code 255 to abort shutdown.
  42.  
  43.     . /etc/rc.d/PUPSTATE
  44.     if [ $DISPLAY ];then #paranoid precaution, check X still running
  45.  
  46.      #120216 offer to set default language in initrd...
  47.      if [ -d /initrd ];then
  48.       GIVEITAGO='yes'
  49.       LANG1=${LANG%_*} #ex: en
  50.       [ "$LANG1" = "en" ] && GIVEITAGO='no'
  51.       if [ -f /var/local/lang2initrd.log ];then #read log from /usr/sbin/lang2initrd
  52.        [ "`grep "^DECLINED ${DISTRO_IDSTRING}" /var/local/lang2initrd.log`" != "" ] && GIVEITAGO='no'
  53.        [ "`grep "^SUCCESS ${DISTRO_IDSTRING}" /var/local/lang2initrd.log`" != "" ] && GIVEITAGO='no'
  54.       fi
  55.       [ "$GIVEITAGO" = "yes" ] && /usr/sbin/lang2initrd $LANG
  56.      fi
  57.      
  58.      HLESS="$(tr ' ' '\n' < /proc/cmdline | grep '^pfix=' | cut -d= -f2 | grep "headless")"
  59.    
  60.      if [ $PUPMODE -eq 5 ];then #first shutdown.
  61.       if [ "$HLESS" == "" ]; then
  62.       shutdownconfig #dlgs for creating save-file.
  63.       #...writes results to /tmp/shutdownconfig_results, which /etc/rc.d/rc.shutdown reads.
  64.       [ $? -eq 255 ] && exit #abort shutdown. 130221
  65.       fi
  66.      fi
  67.    
  68.     fi
  69.  
  70.     #/sbin/pup_event_frontend_d will quit if this file exists...
  71.     [ "$script" = 'wmreboot' ] && echo -n "reboot" > /tmp/wmexitmode.txt
  72.     [ "$script" = 'wmpoweroff' ] && echo -n "poweroff" > /tmp/wmexitmode.txt
  73.     chmod 777 /tmp/wmexitmode.txt
  74.     ;;
  75.  
  76. esac
  77.  
  78. ###########################################################
  79.  
  80. #give time for /sbin/pup_event_frontend_d to quit.
  81. #w478 testing 2.6.18.1 kernel, pup_event_frontend_d did not exit when it
  82. #detected /tmp/wmeximode.txt, but became 'defunct'...
  83. KCNT=0
  84. PSPEFD="`ps -C pup_event_frontend_d | grep 'pup_event_front' | grep -v 'defunct'`"
  85. #while [ "`pidof pup_event_frontend_d`" != "" ];do
  86. while [ "$PSPEFD" != "" ];do
  87.   sleep 0.5
  88.   KCNT=`expr $KCNT + 1`
  89.   [ $KCNT -gt 60 ] && break #30 secs.
  90.   PSPEFD="`ps -C pup_event_frontend_d | grep 'pup_event_front' | grep -v 'defunct'`"
  91. done
  92. sleep 0.2
  93.  
  94. sync
  95.  
  96. #if [ "`pidof xfce4-panel`" != "" ];then
  97.   ##killall xfce4-panel
  98.   #kill `pidof xfce4-panel`
  99.   #exit
  100. #fi
  101.  
  102. #w003
  103. CURRENTWM="`cat /etc/windowmanager`"
  104.  
  105. #Replaced this seciton with blow for loop.
  106. #kill -9 `pidof $CURRENTWM`
  107. #killall -9 jwm
  108. #killall -9 openbox
  109. #killall -9 icewm
  110.  
  111. #This looks like it might be inportant.
  112. while [ "`pidof snapmergepuppy`" ] ; do sleep 1 ; done
  113. sleep 0.2
  114.  
  115. sync
  116.  
  117. kill_WMs(){
  118.    
  119.     for i in xfce4-panel lxsession lxqt-session "$XDG_CURRENT_DESKTOP " `cat /etc/windowmanager` jwm icewm openbox compiz
  120.     do
  121.       case "$i" in #This was from SliTaz
  122.       openbox) openbox --exit; ;;
  123.       lxsession|LXDE|lxde)
  124.          [ -n "$_LXSESSION_PID" ] && kill $_LXSESSION_PID
  125.          ;;
  126.       compiz) killall compiz ;;
  127.       esac
  128.       for pid in `pidof $i` ; do #This was from puppy
  129.         kill $pid || kill -9 $pid
  130.       done
  131.     done
  132. }
  133. kill_Xorg(){ #This branch was taken from puppy  
  134.     for i in X Xorg
  135.     do
  136.       for pid in `pidof $i` ; do
  137.         kill $pid || kill -9 $pid
  138.       done
  139.     done
  140.    
  141.    
  142. }
  143. if [ ! -z $EXIT_IN_XINITRC ] && [ $EXIT_IN_XINITRC -eq 0 ]; then
  144.          #xfce       #lxde     #LXQt        #window managers
  145.   kill_WMs
  146.   kill_Xorg
  147. elif [ "$script" = "wmpoweroff"  ]; then
  148.   exec /sbin/poweroff #see /usr/bin/wmpoweroff
  149. elif [ "$script" = "wmreboot" ]; then
  150.   exec /sbin/reboot #see /usr/bin/wmpoweroff
  151. elif [ "$script" = "wmlogout" ] || [ ! "`id -u`" -eq 0 ]; then
  152.   kill_WMs
  153. else # [ "$script" = "wmexit" ]; then
  154.   if [ $(ps -aux | grep -c slim) -gt 1 ]; then
  155.     /etc/init.d/slim stop
  156.   else
  157.     kill_WMs
  158.     kill_Xorg  
  159.   fi  
  160. fi
  161. #TO review handle inittab code from: https://github.com/puppylinux-woof-CE/woof-CE/blob/8c42322085ba71dcc96c1f2aebf36e01129cfeab/woof-code/rootfs-skeleton/sbin/poweroff#L33
  162.  
  163. ### END ###
RAW Paste Data