daily pastebin goal
7%
SHARE
TWEET

pMirror

a guest Apr 1st, 2013 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/bash
  2. #Pmirror - gui for mirdir
  3. #Sigmund Berglund
  4. #Copyright 2007, 2008, 2009, 2010, 2011, 2012
  5. #120816 rodin.s: i18n
  6. export TEXTDOMAIN=pmirror
  7. . gettext.sh
  8.  
  9. #------------------------------
  10. #Pmirror is released under the GNU General Public License (GPL). You have the right to use and modify this software in any way you like, so long as any derivative works remain under a GPL license.
  11.    
  12. #This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
  13. #See the GNU General Public License homepage for more details. <http://www.gnu.org/licenses/>.
  14. #------------------------------
  15.  
  16. VERSION="0.6.1"
  17. SOURCEDIR=`grep sourcedir $HOME/.pmirror_config 2> /dev/null | sed -e s/^.*\=//g`
  18. MIRRORDIR=`grep mirrordir $HOME/.pmirror_config 2> /dev/null | sed -e s/^.*\=//g`
  19. EXCEPTION_FILE=`grep exception_file $HOME/.pmirror_config 2> /dev/null | sed -e s/^.*\=//g`
  20. [ ! "$EXCEPTION_FILE" ] && EXCEPTION_FILE=none
  21. echo "echo " $SOURCEDIR > /tmp/pm_source_dir
  22. echo "echo " $MIRRORDIR > /tmp/pm_mirror_dir
  23. echo "echo " $EXCEPTION_FILE > /tmp/pm_exception_dir
  24. echo -e "\c" > /tmp/pm_mirdir
  25. chmod 777 /tmp/pm_source_dir
  26. chmod 777 /tmp/pm_mir*
  27. chmod 777 /tmp/pm_exc*
  28.  
  29. #-----get nr of days beetween last mirrorday and today
  30. MIRRORDATE=`grep mirrordate $HOME/.pmirror_config 2> /dev/null | sed -e s/^.*\=//g`
  31. TODAY_SEC=`date +%s`
  32. TODAY_DAYS=`expr $TODAY_SEC / 60 / 60 / 24`
  33. TMP=`echo $MIRRORDATE | sed -e "s/\// /g" | awk '{print $2} {print $1} {print $3}'`
  34. MIRRORDATE1=`echo $TMP | sed -e "s/ /\//g"`
  35. MIRRORDATE_SEC=`date -d $MIRRORDATE1 +%s 2> /dev/null`
  36. MIRRORDATE_DAYS=`expr $MIRRORDATE_SEC / 60 / 60 / 24 2> /dev/null`
  37. DAYS=`expr $TODAY_DAYS - $MIRRORDATE_DAYS 2> /dev/null`
  38. #-----
  39. if test -z $MIRRORDATE; then
  40.         echo -e " $(gettext 'It seems to be your first run of Pmirror.\n Please read HELP for information.')" > /tmp/pm_progress
  41. else
  42.         echo -e " `eval_gettext \"Last Mirror of listed directory was "\\\$DAYS" days ago.\"`" > /tmp/pm_progress
  43. fi
  44.  
  45. export Pmirror='
  46. <window title="'$(gettext 'Pmirror - mirror/backup utility')'">
  47. <vbox>
  48. <hbox>
  49.  <text><label>'$(gettext 'Source dir')'</label></text>
  50.  <entry accept="directory"><variable>SOURCEDIR</variable><input>/tmp/pm_source_dir</input></entry>
  51.  <button>
  52.   <input file stock="gtk-open"></input>
  53.   <action type="fileselect">SOURCEDIR</action>
  54.  </button>
  55. </hbox>
  56. <hbox>
  57.  <text><label>'$(gettext 'Mirror dir')'</label></text>
  58.  <entry accept="directory"><variable>MIRRORDIR</variable><input>/tmp/pm_mirror_dir</input></entry>
  59.  <button>
  60.   <input file stock="gtk-open"></input>
  61.   <action type="fileselect">MIRRORDIR</action>
  62.  </button>
  63. </hbox>
  64. <frame '$(gettext 'Options')'>
  65.  <checkbox>
  66.   <label>'$(gettext 'Only simulate mirror')'</label>
  67.   <variable>CHECK1</variable>
  68.   <default>yes</default>
  69.  </checkbox>
  70.  <checkbox><label>'$(gettext 'View information')'</label><variable>CHECK2</variable></checkbox>
  71.  <checkbox>
  72.   <label>'$(gettext 'Quick file compare')'</label>
  73.   <variable>CHECK3</variable>
  74.   <default>yes</default>
  75.  </checkbox>
  76.  <checkbox><label>'$(gettext 'Do not compare ownership')'</label><variable>CHECK4</variable></checkbox>
  77.  <checkbox><label>'$(gettext 'Do not compare date/time')'</label><variable>CHECK5</variable></checkbox>
  78.  <hbox>
  79.   <text><label>'$(gettext 'Exception file')'</label></text>
  80.   <entry><variable>EXCEPTION_FILE</variable><input>/tmp/pm_exception_dir</input></entry>
  81.   <button>
  82.    <input file stock="gtk-open"></input>
  83.         <action type="fileselect">EXCEPTION_FILE</action>
  84.   </button>
  85.  </hbox>
  86. </frame>
  87. <frame '$(gettext 'info')'>
  88.  <text><input file>/tmp/pm_progress</input></text>
  89. </frame>
  90. <hbox>
  91.  <button help>
  92.   <action>`Xdialog --wrap --screencenter --left --title "'$(gettext 'Pmirror - HELP')'" --msgbox "'$(gettext 'Pmirror is a simple backup system to make one directory like another. First run it will copy the entire source-directory to the mirror-directory. The mirror function will then just update the mirror-directory. It will delete files on the mirror-directory if they dont exist on source-directory. Be careful, think twice and check settings again.\n\nThe mirror-directory should not be on the same harddisk that you stores your main data. Do NOT think your data is safe when saving mirror-files on another partition. It is still the same disk, and when it crashes, it all does. If you have only one disk, it may be better to burn files to CD/DVD.\n\n- Pmirror is a GUI for the mirdir package (19k).\n- $HOME/ is where your personal data is stored (e-mail, bookmarks...)\n- Config file: $HOME/.pmirror_config. Created after first mirror.\n- See also mirdir documentation.\n- No warranty.\n\n- Sigmund Berglund --- September 2007')'" 600x0`</action>
  93.  </button>
  94.  <button cancel></button>
  95.  <button ok></button>
  96. </hbox>
  97. </vbox>
  98. </window>'
  99.  
  100. I=$IFS; IFS=""
  101. for STATEMENTS in  $(gtkdialog3 --program Pmirror); do
  102.         eval $STATEMENTS
  103. done
  104. IFS=$I
  105. if [ "$EXIT" = "OK" ]; then
  106.         SOURCEDIR=`echo "$SOURCEDIR"/ | sed -e "s%//%/%g"`
  107.         MIRRORDIR=`echo "$MIRRORDIR"/ | sed -e "s%//%/%g"`
  108.         #-----bulid mirdir command
  109.         echo -e "mirdir \c" > /tmp/pm_mirdir
  110.         echo -e "-e "$EXCEPTION_FILE "\c" >> /tmp/pm_mirdir
  111.         if test $CHECK1 = true; then
  112.                 echo -e "-i \c" >> /tmp/pm_mirdir
  113.                 echo -e "\n $(gettext 'Pmirror will now simulate the backup process.\n If it all goes right, turn off the simulate option,\n and make a real mirror ....\n\n Choose OK to continue, and CANCEL to quit.')" > /tmp/pm_progress
  114.         else
  115.                 echo -e "\n\n `eval_gettext \"WARNING!!!\n\n\n It may happend that Pmirror will delete files in \n \\\$MIRRORDIR .... \n\n Choose OK to continue, and CANCEL to quit.\"`" > /tmp/pm_progress
  116.         fi
  117.         if test $CHECK2 = true; then echo -e "-v \c" >> /tmp/pm_mirdir;fi
  118.         if test $CHECK3 = false; then echo -e "-s \c" >> /tmp/pm_mirdir;fi
  119.         if test $CHECK4 = true; then echo -e "-o \c" >> /tmp/pm_mirdir;fi
  120.         if test $CHECK5 = true; then echo -e "-d \c" >> /tmp/pm_mirdir;fi
  121.         echo -e '"'"$SOURCEDIR"'"' "\c" >> /tmp/pm_mirdir
  122.         echo -e '"'"$MIRRORDIR"'"' "\c" >> /tmp/pm_mirdir
  123.        
  124.         Xdialog --title "Pmirror" --screen-center --logbox /tmp/pm_progress 400x370
  125.         if test "$?" = "0"; then
  126.                 #-----Run mirdir
  127.                 Xdialog --title "Pmirror" --screen-center --no-cancel --logbox /tmp/pm_progress 400x370 &
  128.                 /tmp/pm_mirdir >> /tmp/pm_progress 2>&1
  129.                 FINALCHECK=`cat /tmp/pm_progress | grep -m 1 "compared"`
  130.                 if test -n "$FINALCHECK"; then
  131.                         echo -e "\n\n\n$(gettext 'It seems that all went well.')\n" >> /tmp/pm_progress
  132.                 else
  133.                         echo -e "\n\n\n$(gettext 'Something went wrong during backup.\n- Are the "mirdir" package installed?\n- Does source- and mirror-directory exist?\n- Have you defined a exception file in right terms?\n- Read messages above and Help.')" >> /tmp/pm_progress
  134.                 fi
  135.                 #-----update config-file, if mirror without simulate option
  136.                 if test $CHECK1 = false; then
  137.                         echo "mirrordate=`date +%d/%m/%Y`" > $HOME/.pmirror_config
  138.                         echo "sourcedir=$SOURCEDIR" >> $HOME/.pmirror_config
  139.                         echo "mirrordir=$MIRRORDIR" >> $HOME/.pmirror_config
  140.                         echo "exception_file=$EXCEPTION_FILE" >> $HOME/.pmirror_config
  141.                        
  142.                         echo -e "$(gettext 'Configuration file is updated.')\n" >> /tmp/pm_progress
  143.                 fi
  144.         else
  145.                 rm -f /tmp/pm_*
  146.                 exit
  147.         fi
  148. else
  149.         rm -f /tmp/pm_*
  150.         exit
  151. fi
RAW Paste Data
Top