Advertisement
devinteske

Desktop start script for conky

Jan 3rd, 2020
688
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.37 KB | None | 0 0
  1. #!/bin/sh
  2. ############################################################ IDENT(1)
  3. #
  4. # $Title: Script for starting conky and initializing random desktop $
  5. #
  6. ############################################################ CONFIGURATION
  7.  
  8. #nohup /bin/sh -c 'dbus-monitor > monitor.$$.log 2>&1' &
  9.  
  10. #
  11. # Conky configuration file
  12. #
  13. CONKY_CONFIG=theme/conky/ident.conkyrc
  14. CONKY_GNOME_CONFIG=theme/conky/ident-gnome-vmware.conkyrc
  15. CONKY_KDE_CONFIG=theme/conky/ident-kde-vmware.conkyrc
  16.  
  17. #
  18. # Where to find wallpaper
  19. # NB: Relative paths are in home directory
  20. #
  21. WALLPAPER=Wallpaper
  22.  
  23. #
  24. # How often (in seconds) to rotate the desktop
  25. # NB: Rotation is to a random image in WALLPAPER directory
  26. # MB: Should be divisible by DESKTOP_TIMEOUT
  27. #
  28. DESKTOP_INTERVAL=600 # 10 minutes
  29. DESKTOP_TIMEOUT=10 # seconds
  30.  
  31. #
  32. # Wait for DBus registry elements
  33. # NB: Any one will trigger start or timeout
  34. #
  35. DBUS_TIMEOUT=60
  36. DBUS_GNOME=org.gnome.SessionManager
  37. DBUS_KDE=org.kde.kuiserver
  38. DBUS_WAIT_FOR="
  39.     $DBUS_GNOME
  40.     $DBUS_KDE
  41. " # END-QUOTE
  42.  
  43. ############################################################ MAIN
  44.  
  45. cd # Home directory
  46.  
  47. #
  48. # Short-hand
  49. #
  50. DBUS_LISTNAMES=$( echo dbus-send \
  51.     --session           \
  52.     --dest=org.freedesktop.DBus \
  53.     --type=method_call      \
  54.     --print-reply           \
  55.     /org/freedesktop/DBus       \
  56.     org.freedesktop.DBus.ListNames
  57. )
  58. DBUS_GNOME_RE='\<'"$( echo "$DBUS_GNOME" | awk 'gsub(/\./, "\\.")||1' )"'\>'
  59. DBUS_KDE_RE='\<'"$( echo "$DBUS_KDE" | awk 'gsub(/\./, "\\.")||1' )"'\>'
  60. DBUS_WAIT_RE='\<\('"$( echo "$DBUS_WAIT_FOR" | xargs -n 1 | awk '
  61.     {
  62.         re = $0
  63.         gsub(/\./, "\\.", re)
  64.         buf = buf "\\|" re
  65.     }
  66.     END { print substr(buf, 3) }
  67. ' )"'\)\>'
  68.  
  69. #
  70. # Start conky
  71. #
  72. pkill -f conky > /dev/null 2>&1
  73. sleep 1
  74. nohup /bin/sh -c "
  75.     countup=0
  76.     names=
  77.     while : forever ; do
  78.         names=\$( $DBUS_LISTNAMES )
  79.         echo \"\$names\" | grep -q '$DBUS_WAIT_RE' && break
  80.         [ \$countup -gt $DBUS_TIMEOUT ] && break
  81.         sleep 5
  82.         countup=\$(( \$countup + 5 ))
  83.     done
  84.     if echo \"\$names\" | grep -q '$DBUS_GNOME_RE'; then
  85.         config=\"$CONKY_GNOME_CONFIG\"
  86.     elif echo \"\$names\" | grep -q '$DBUS_KDE_RE'; then
  87.         config=\"$CONKY_KDE_CONFIG\"
  88.     else
  89.         config=\"$CONKY_CONFIG\"
  90.     fi
  91.     nohup conky -c \"\$config\" > /dev/null 2>&1 &
  92. " > /dev/null 2>&1 &
  93.  
  94. #
  95. # Start desktop worker
  96. # NB: Rotates Wallpaper every $DESKTOP_INTERVAL seconds
  97. #
  98. export WALLPAPER
  99. exec 9<<'EOF'
  100. set -e # errexit
  101. wallpapers=$( find $WALLPAPER -mindepth 1 -maxdepth 1 -type f | sort )
  102. nwallpapers=$( echo "$wallpapers" | awk 'END{print NR}' )
  103. n=$( awk -v max=$nwallpapers 'BEGIN {
  104.     srand()
  105.     srand(srand())
  106.     r = sprintf("%0.f", rand() * max)
  107.     print (r > 0 ? r : 1)
  108. }' )
  109. wallpaper=$( echo "$wallpapers" | awk -v n=$n 'NR==n' )
  110. [ "$wallpaper" ] && hsetroot -fill "$wallpaper"
  111. EOF
  112. DESKTOP_WORKER=$( cat <&9 )
  113. export DESKTOP_WORKER
  114. nohup /bin/sh -ec "
  115.     countdown=0
  116.     countup=0
  117.     while ! $DBUS_LISTNAMES | grep -q '$DBUS_WAIT_RE'; do
  118.         [ \$countup -gt $DBUS_TIMEOUT ] && break
  119.         sleep 5
  120.         countup=\$(( \$countup + 5 ))
  121.     done
  122.     while pgrep -q conky; do
  123.         if [ \$countdown -le 0 ]; then
  124.             eval \"\$DESKTOP_WORKER\"
  125.             countdown=$DESKTOP_INTERVAL
  126.         else
  127.             sleep $DESKTOP_TIMEOUT
  128.             countdown=\$(( \$countdown - $DESKTOP_TIMEOUT ))
  129.         fi
  130.     done
  131. " > /dev/null 2>&1 &
  132.  
  133. ################################################################################
  134. # END
  135. ################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement