CrunchBang Linux Pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

CrunchBang Linux Pastebin

Posted by corenominal on Wed 29th Apr 08:08 (modification of post by view diff)
View followups from ANGE, HL and Josh | download | new post

  1. #!/bin/bash
  2. # Author:
  3. #   Philip Newborough <corenominal@corenominal.org>
  4. # Copyright:
  5. #   © 2008 Philip Newborough <corenominal@corenominal.org>
  6. # License:
  7. #   This program is free software; you can redistribute it and/or
  8. #   modify it under the terms of the GNU Lesser General Public
  9. #   License as published by the Free Software Foundation; either
  10. #   version 2.1 of the License, or (at your option) any later version.
  11. #
  12. #   This program is distributed in the hope that it will be useful,
  13. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. #   Lesser General Public License for more details.
  16. #
  17. #   You should have received a copy of the GNU Lesser General Public
  18. #   License along with this library; if not, write to the Free Software
  19. #   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  20. #
  21. #   On Debian systems, the complete text of the GNU Lesser General Public
  22. #   License V2.1 can be found in the file `/usr/share/common-licenses/LGPL-2.1'.
  23. #-------------------------------------------------------------------------------   
  24. # Display help
  25. if [ "$1" = "" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  26.     echo "Usage:"
  27.     echo "  rotate-wallpaper --path DIRECTORY"
  28.     echo ""
  29.     echo "    -h, --help"
  30.     echo "          Shows this message and exits."
  31.     echo "    -p, --path"
  32.     echo "          Set path to directory containing images."
  33.     echo ""
  34.     exit   
  35. fi
  36. if [ "$1" = "-p" ] || [ "$1" = "--path" ];then
  37.     if [ ! "$2" = "" ];then
  38.         # Set the path to your wallpaper directory
  39.         WALLPAPERS=$2
  40.         # Sanity check. Does wallpaper directory exist
  41.         if [ ! -d $WALLPAPERS ]; then
  42.             echo "Oops! Specified directory does not exist."
  43.             echo ""
  44.             rotate-wallpaper --help
  45.             exit 1
  46.         fi
  47.         # Sanity check. Is wallpapers directory completely empty of files?
  48.         if [ ! "$(ls -A $WALLPAPERS)" ]; then
  49.             echo "Oops! No images found within specified directory."
  50.             echo ""
  51.             rotate-wallpaper --help
  52.             exit 1
  53.         fi
  54.         # Sanity check. Is wallpapers directory empty of images?
  55.         # + Build query
  56.         QUERY=""
  57.         if [ "$(ls $WALLPAPERS/*.jpg 2> /dev/null)" ]; then
  58.             QUERY="$QUERY$WALLPAPERS/*.jpg "
  59.         fi
  60.         if [ "$(ls $WALLPAPERS/*.JPG 2> /dev/null)" ]; then
  61.             QUERY="$QUERY$WALLPAPERS/*.JPG "
  62.         fi
  63.         if [ "$(ls -l $WALLPAPERS/*.PNG 2> /dev/null)" ]; then
  64.             QUERY="$QUERY$WALLPAPERS/*.PNG "
  65.         fi
  66.         if [ "$(ls -l $WALLPAPERS/*.png 2> /dev/null)" ]; then
  67.             QUERY="$QUERY$WALLPAPERS/*.png "
  68.         fi
  69.         if [ "$QUERY" = "" ];then
  70.             echo "Oops! No images found within specified directory."
  71.             echo ""
  72.             rotate-wallpaper --help
  73.             exit 1
  74.         fi
  75.         # Sanity check. Does config directory exist?
  76.         if [ ! -d ~/.config/rotate-wallpaper ]; then
  77.             mkdir ~/.config/rotate-wallpaper
  78.         fi
  79.         # Sanity check. Does config file exist?
  80.         if [ ! -f ~/.config/rotate-wallpaper/count ]; then
  81.             touch ~/.config/rotate-wallpaper/count
  82.             echo "0" > ~/.config/rotate-wallpaper/count
  83.         fi
  84.         # Count number of wallpapers
  85.         NO_OF_WALLPAPERS=0
  86.         for file in $QUERY; do
  87.             if [ ! -d "$file" ];then
  88.                 NO_OF_WALLPAPERS=$(( NO_OF_WALLPAPERS+1 ))
  89.             fi
  90.         done
  91.         # Read in number of last wallpaper displayed, or start from 1
  92.         PREVIOUS_WALLPAPER="$(cat ~/.config/rotate-wallpaper/count)"
  93.         NEW_WALLPAPER=$(( PREVIOUS_WALLPAPER+1 ))
  94.         # Do we need to loop back to 1?
  95.         if [ $NEW_WALLPAPER -gt $NO_OF_WALLPAPERS ];then
  96.             NEW_WALLPAPER=1
  97.         fi
  98.         # Set wallpaper
  99.         CNT=1
  100.         for file in $QUERY; do
  101.             if [ $CNT = $NEW_WALLPAPER ]; then
  102.                 if [ ! -d "$file" ];then
  103.                     FILE_TYPE=$(file -i "$file")
  104.                     if [ "$FILE_TYPE" = "$file: image/png" ] || \
  105.                     [ "$FILE_TYPE" = "$file: image/jpeg" ];then
  106.                         nitrogen --set-scaled "$file"
  107.                     fi
  108.                 fi
  109.             fi
  110.             CNT=$(( CNT+1 ))
  111.         done
  112.         # Save count and exit
  113.         echo "$NEW_WALLPAPER" > ~/.config/rotate-wallpaper/count
  114.         exit
  115.     else
  116.         # Show error if no directory given
  117.         echo "Oops! Image directory not specified."
  118.         echo ""
  119.         rotate-wallpaper --help
  120.         exit 1
  121.     fi
  122. fi
  123. # If all else fails
  124. echo "Oops! Invalid command. Have a clue..."
  125. rotate-wallpaper --help
  126. exit 1

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me