Advertisement
Guest User

md5sum-mint 0.1 created by shane <linuxmint.com>

a guest
Sep 16th, 2010
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.06 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. #
  4. # md5sum-mint 0.1 created by shane <linuxmint.com>
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  
  18. # USA
  19. # dependencies
  20. #   bash
  21. #       zenity
  22.  
  23. ################################################
  24. #       TRANSLATIONS
  25. #-----------------------------------------------
  26. #   Default = English
  27. title="MD5 Checksum                     "
  28. title1="MD5 Checksum - Select a file    "
  29. title2="MD5 Checksum - Error            "
  30. text1="Select a file"
  31. text2="Calculating MD5 Checksum...   "
  32. text3="MD5 Checksum aborted"
  33. text4="The MD5 Checksum is:"
  34. text5="The md5sum file is:"
  35. text6="<b>Select the actions you wish to perform</b>"
  36. error1="You do not have read permission"
  37. error2="You do not have write permission"
  38. error3="No action selected. Exiting."
  39. action0="Action"
  40. action1="Display the calculated md5sum"
  41. action2="Save the md5sum to a file"
  42. case $LANG in
  43.     ######## Japanese by blowback ########
  44.     ja* )
  45.         title="MD5チェックサム                     "
  46.         title1="MD5チェックサム - ファイルの選択    "
  47.         title2="MD5チェックサム - エラー           "
  48.         text1="ファイルの選択"
  49.         text2="MD5チェックサムを計算しています...   "
  50.         text3="MD5チェックサムが中止されました"
  51.         text4="MD5チェックサム:"
  52.         text5="md5sumファイル:"
  53.         text6="<b>実行したいアクションを選んでください</b>"
  54.         error1="読み込み権がありません"
  55.         error2="書き込み権がありません"
  56.         error3="アクションが選択されていません。終了します。"
  57.         action0="アクション"
  58.         action1="計算したmd5sumを表示"
  59.         action2="md5sumをファイルに保存"
  60. esac
  61. ################################################
  62.  
  63. #Check if running under X
  64. xcheck=`tty | cut -d '/' -f3`
  65. if [ $xcheck != "pts" ]
  66. then
  67.     echo "Error: md5sum-mint must be run under X"
  68.     exit 1
  69. fi
  70.  
  71. #If no file is selected
  72. if [ -z "$1" ]
  73. then
  74.     cd $HOME
  75.     input=$(zenity --file-selection --title="$title1")
  76. else
  77. #If a file is selected
  78.     if [ -f "$1" ]
  79.     then
  80.         input="$1"
  81.     else
  82. #If a directory is selected
  83.         cd "$1"
  84.         input=$(zenity --file-selection --title="$title1")
  85.     fi
  86. fi
  87.  
  88. #If still no file is selected (operation cancelled)
  89. if [ -z "$input" ]
  90. then
  91.     exit 1
  92. fi
  93.  
  94. #Check read permissions for input file
  95. if [ ! -r "$input" ]
  96. then
  97.     zenity --error --title="$title" --text "<b>$input:</b>
  98.  
  99. $error1"
  100.     exit 2
  101. fi
  102.  
  103. #Get location and filename from input
  104. wdir=`dirname "$input"`
  105. file=`basename "$input"`
  106.  
  107. #cd into directory
  108. cd "$wdir"
  109.  
  110. #debug
  111. #zenity --info --text "Debug:
  112. #dir is $wdir
  113. #file is $file"
  114.  
  115. #Actions selection dialog
  116. action=$(zenity --list --title="$title" --text "$text6" --checklist --column "" --column "$action0" TRUE "$action1" FALSE "$action2" --separator=":")
  117.  
  118. #debug
  119. #zenity --info --text "Debug:
  120. #$action ."
  121.  
  122. #If no action selected
  123. if [ -z "$action" ]
  124. then
  125.     zenity --error --title="$title2" --text "$error3"
  126.     exit 3
  127. fi
  128.  
  129. #Check if saving to file is selected
  130. if [ "$action" != "$action1" ]
  131. then
  132.  
  133. #Check write permission to directory
  134.     if [ ! -w "$wdir" ]
  135.     then
  136.         zenity --error --title="$title2" --text "<b>$wdir:</b>
  137.  
  138. $error2"
  139.         exit 4
  140.     fi
  141. fi
  142.  
  143. #debug
  144. #zenity --info --text "Debug:
  145. #$action"
  146.  
  147. #Calculate md5sum, progress dialog and output to file
  148. md5sum "$file" | tee >(cut -d ' ' -f1 > /tmp/sum) | (zenity --progress --title="$title" --pulsate --auto-kill --auto-close --text "$text2")
  149.  
  150. #Find the zenity progress dialog
  151. running=`ps aux | grep "$text2" | sed '/grep/ d'`
  152.  
  153. #Loop while progress dialog is running
  154. until [ -z "$running" ]
  155. do
  156.     sleep 1
  157.     running=`ps aux | grep "$text2" | sed '/grep/ d'`
  158. done
  159.  
  160. #Check if md5sum is still running after zenity dialog has closed
  161.  
  162. sum=`cat /tmp/sum`
  163. rm /tmp/sum
  164.  
  165. #debug
  166. #zenity --info --text "Debug:
  167. #$sum"
  168.  
  169. #Completed successfully! Now for the final actions!
  170.  
  171. #action for display and save
  172. if [ "$action" = "$action1:$action2" ]
  173. then
  174.     rm "$file".md5sum
  175.     echo $sum > "$file".md5sum
  176.     zenity --info --title="$title" --text "<b>$file:</b>
  177.  
  178. $text4
  179. <b>$sum</b>
  180.  
  181. $text5
  182. <b>$file.md5sum</b>"
  183.     exit
  184. fi
  185.  
  186. #action for display only
  187. if [ "$action" = "$action1" ]
  188. then
  189.     zenity --info --title="$title" --text "<b>$file:</b>
  190.  
  191. $text4
  192. <b>$sum</b>"
  193.     exit
  194. fi
  195.  
  196. #action for save only
  197. if [ "$action" = "$action2" ]
  198. then
  199.     rm "$file".md5sum
  200.     echo $sum > "$file".md5sum
  201.     zenity --info --title="$title" --text "<b>$file:</b>
  202.  
  203. $text5
  204. <b>$file.md5sum</b>"
  205.     exit
  206. fi
  207. killall md5sum
  208. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement