Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- ############################################################ IDENT(1)
- #
- # $Title: Script for starting conky and initializing random desktop $
- #
- ############################################################ CONFIGURATION
- #nohup /bin/sh -c 'dbus-monitor > monitor.$$.log 2>&1' &
- #
- # Conky configuration file
- #
- CONKY_CONFIG=theme/conky/ident.conkyrc
- CONKY_GNOME_CONFIG=theme/conky/ident-gnome-vmware.conkyrc
- CONKY_KDE_CONFIG=theme/conky/ident-kde-vmware.conkyrc
- #
- # Where to find wallpaper
- # NB: Relative paths are in home directory
- #
- WALLPAPER=Wallpaper
- #
- # How often (in seconds) to rotate the desktop
- # NB: Rotation is to a random image in WALLPAPER directory
- # MB: Should be divisible by DESKTOP_TIMEOUT
- #
- DESKTOP_INTERVAL=600 # 10 minutes
- DESKTOP_TIMEOUT=10 # seconds
- #
- # Wait for DBus registry elements
- # NB: Any one will trigger start or timeout
- #
- DBUS_TIMEOUT=60
- DBUS_GNOME=org.gnome.SessionManager
- DBUS_KDE=org.kde.kuiserver
- DBUS_WAIT_FOR="
- $DBUS_GNOME
- $DBUS_KDE
- " # END-QUOTE
- ############################################################ MAIN
- cd # Home directory
- #
- # Short-hand
- #
- DBUS_LISTNAMES=$( echo dbus-send \
- --session \
- --dest=org.freedesktop.DBus \
- --type=method_call \
- --print-reply \
- /org/freedesktop/DBus \
- org.freedesktop.DBus.ListNames
- )
- DBUS_GNOME_RE='\<'"$( echo "$DBUS_GNOME" | awk 'gsub(/\./, "\\.")||1' )"'\>'
- DBUS_KDE_RE='\<'"$( echo "$DBUS_KDE" | awk 'gsub(/\./, "\\.")||1' )"'\>'
- DBUS_WAIT_RE='\<\('"$( echo "$DBUS_WAIT_FOR" | xargs -n 1 | awk '
- {
- re = $0
- gsub(/\./, "\\.", re)
- buf = buf "\\|" re
- }
- END { print substr(buf, 3) }
- ' )"'\)\>'
- #
- # Start conky
- #
- pkill -f conky > /dev/null 2>&1
- sleep 1
- nohup /bin/sh -c "
- countup=0
- names=
- while : forever ; do
- names=\$( $DBUS_LISTNAMES )
- echo \"\$names\" | grep -q '$DBUS_WAIT_RE' && break
- [ \$countup -gt $DBUS_TIMEOUT ] && break
- sleep 5
- countup=\$(( \$countup + 5 ))
- done
- if echo \"\$names\" | grep -q '$DBUS_GNOME_RE'; then
- config=\"$CONKY_GNOME_CONFIG\"
- elif echo \"\$names\" | grep -q '$DBUS_KDE_RE'; then
- config=\"$CONKY_KDE_CONFIG\"
- else
- config=\"$CONKY_CONFIG\"
- fi
- nohup conky -c \"\$config\" > /dev/null 2>&1 &
- " > /dev/null 2>&1 &
- #
- # Start desktop worker
- # NB: Rotates Wallpaper every $DESKTOP_INTERVAL seconds
- #
- export WALLPAPER
- exec 9<<'EOF'
- set -e # errexit
- wallpapers=$( find $WALLPAPER -mindepth 1 -maxdepth 1 -type f | sort )
- nwallpapers=$( echo "$wallpapers" | awk 'END{print NR}' )
- n=$( awk -v max=$nwallpapers 'BEGIN {
- srand()
- srand(srand())
- r = sprintf("%0.f", rand() * max)
- print (r > 0 ? r : 1)
- }' )
- wallpaper=$( echo "$wallpapers" | awk -v n=$n 'NR==n' )
- [ "$wallpaper" ] && hsetroot -fill "$wallpaper"
- EOF
- DESKTOP_WORKER=$( cat <&9 )
- export DESKTOP_WORKER
- nohup /bin/sh -ec "
- countdown=0
- countup=0
- while ! $DBUS_LISTNAMES | grep -q '$DBUS_WAIT_RE'; do
- [ \$countup -gt $DBUS_TIMEOUT ] && break
- sleep 5
- countup=\$(( \$countup + 5 ))
- done
- while pgrep -q conky; do
- if [ \$countdown -le 0 ]; then
- eval \"\$DESKTOP_WORKER\"
- countdown=$DESKTOP_INTERVAL
- else
- sleep $DESKTOP_TIMEOUT
- countdown=\$(( \$countdown - $DESKTOP_TIMEOUT ))
- fi
- done
- " > /dev/null 2>&1 &
- ################################################################################
- # END
- ################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement