12.1.8. zenity 的 shell 脚本案例

下面是一个简单的脚本,它通过 dvdisaster(1) 创建了带有 RS02 补充数据的 ISO 映像。

  1. #!/bin/sh -e
  2. # gmkrs02 : Copyright (C) 2007 Osamu Aoki <osamu@debian.org>, Public Domain
  3. #set -x
  4. error_exit()
  5. {
  6. echo "$1" >&2
  7. exit 1
  8. }
  9. # Initialize variables
  10. DATA_ISO="$HOME/Desktop/iso-$$.img"
  11. LABEL=$(date +%Y%m%d-%H%M%S-%Z)
  12. if [ $# != 0 ] && [ -d "$1" ]; then
  13. DATA_SRC="$1"
  14. else
  15. # Select directory for creating ISO image from folder on desktop
  16. DATA_SRC=$(zenity --file-selection --directory \
  17. --title="Select the directory tree root to create ISO image") \
  18. || error_exit "Exit on directory selection"
  19. fi
  20. # Check size of archive
  21. xterm -T "Check size $DATA_SRC" -e du -s $DATA_SRC/*
  22. SIZE=$(($(du -s $DATA_SRC | awk '{print $1}')/1024))
  23. if [ $SIZE -le 520 ] ; then
  24. zenity --info --title="Dvdisaster RS02" --width 640 --height 400 \
  25. --text="The data size is good for CD backup:\\n $SIZE MB"
  26. elif [ $SIZE -le 3500 ]; then
  27. zenity --info --title="Dvdisaster RS02" --width 640 --height 400 \
  28. --text="The data size is good for DVD backup :\\n $SIZE MB"
  29. else
  30. zenity --info --title="Dvdisaster RS02" --width 640 --height 400 \
  31. --text="The data size is too big to backup : $SIZE MB"
  32. error_exit "The data size is too big to backup :\\n $SIZE MB"
  33. fi
  34. # only xterm is sure to have working -e option
  35. # Create raw ISO image
  36. rm -f "$DATA_ISO" || true
  37. xterm -T "genisoimage $DATA_ISO" \
  38. -e genisoimage -r -J -V "$LABEL" -o "$DATA_ISO" "$DATA_SRC"
  39. # Create RS02 supplemental redundancy
  40. xterm -T "dvdisaster $DATA_ISO" -e dvdisaster -i "$DATA_ISO" -mRS02 -c
  41. zenity --info --title="Dvdisaster RS02" --width 640 --height 400 \
  42. --text="ISO/RS02 data ($SIZE MB) \\n created at: $DATA_ISO"
  43. # EOF

你可能想要在桌面创建一个启动器,其中的命令设置为类似 “/usr/local/bin/gmkrs02 %d” 的形式。