|
Lines 1-11
Link Here
|
| 1 |
--- sh/rdup-simple.in.orig 2009-10-09 23:37:15.000000000 -0700 |
1 |
--- ./sh/rdup-simple.in.orig 2010-03-21 10:17:54.000000000 -0700 |
| 2 |
+++ sh/rdup-simple.in 2009-10-09 23:44:36.000000000 -0700 |
2 |
+++ ./sh/rdup-simple.in 2010-03-30 11:42:33.000000000 -0700 |
| 3 |
@@ -41,7 +41,7 @@ |
3 |
@@ -1,16 +1,19 @@ |
|
|
4 |
-#!/bin/bash |
| 5 |
+#!/bin/sh |
| 6 |
|
| 7 |
# updates a hardlinked backup |
| 8 |
# licensed under the GPL version 3 |
| 9 |
# Copyright Miek Gieben, 2007 - 2010 |
| 10 |
# rewritten for rdup-up and rdup-tr |
| 11 |
+# |
| 12 |
+# Revised 29 Mar 2010 by corky1951 AT comcast.net |
| 13 |
+# to use /bin/sh rather than bash |
| 14 |
|
| 15 |
echo2() { |
| 16 |
echo "** $PROGNAME: $@" >&2 |
| 17 |
} |
| 18 |
|
| 19 |
version() { |
| 20 |
- echo "rdup @PACKAGE_VERSION@" |
| 21 |
+ echo "@PACKAGE_VERSION@" |
| 4 |
} |
22 |
} |
| 5 |
|
23 |
|
| 6 |
PROGNAME=$0 |
24 |
copy_and_link() { |
| 7 |
-NOW=`date +%Y%m/%d` |
25 |
@@ -31,23 +34,24 @@ |
| 8 |
+NOW=`gdate +%Y%m/%d` |
26 |
TOPDIR="$1" |
| 9 |
DAYS=8 |
27 |
|
| 10 |
ssh= |
28 |
if $dry; then return 1; fi |
| 11 |
trans= |
29 |
- [[ -z $TOPDIR ]] && exit 2 |
|
|
30 |
- [[ -d $TOPDIR/$TODAY ]] && exit 0 |
| 31 |
+ [ -z "$TOPDIR" ] && exit 2 |
| 32 |
+ [ -d $TOPDIR/$TODAY ] && exit 0 |
| 33 |
|
| 34 |
if ! mkdir -p $TOPDIR/$TODAY; then |
| 35 |
exit 2 |
| 36 |
fi |
| 37 |
|
| 38 |
- let i=1 |
| 39 |
- while [[ $i -le $LOOKBACK ]]; do |
| 40 |
- D=$(date $DATESTR --date "$i days ago") |
| 41 |
- if [[ -d $TOPDIR/$D ]]; then |
| 42 |
- if ! cp -plr $TOPDIR/$D/* $TOPDIR/$TODAY; then |
| 43 |
+ i=1 |
| 44 |
+ while [ $i -le $LOOKBACK ]; do |
| 45 |
+ adjust=`printf %dd $i` |
| 46 |
+ D=$(date -v-$adjust $DATESTR) |
| 47 |
+ if [ -d $TOPDIR/$D ]; then |
| 48 |
+ if ! cp -plR $TOPDIR/$D/* $TOPDIR/$TODAY; then |
| 49 |
exit 2 |
| 50 |
fi |
| 51 |
exit 0 |
| 52 |
fi |
| 53 |
- let i=i+1 |
| 54 |
+ i=$((i+1)) |
| 55 |
done |
| 56 |
exit 1 |
| 57 |
} |
| 58 |
@@ -105,7 +109,7 @@ |
| 59 |
case $o in |
| 60 |
a) atime=" -a " ;; |
| 61 |
E) |
| 62 |
- if [[ -z "$OPTARG" ]]; then |
| 63 |
+ if [ -z "$OPTARG" ]; then |
| 64 |
echo2 "-E needs an argument" |
| 65 |
exit 1 |
| 66 |
fi |
| 67 |
@@ -116,11 +120,11 @@ |
| 68 |
pathtrans="-$o $OPTARG"; |
| 69 |
;; |
| 70 |
k) |
| 71 |
- if [[ -z "$OPTARG" ]]; then |
| 72 |
+ if [ -z "$OPTARG" ]; then |
| 73 |
echo2 "-k needs an argument" |
| 74 |
exit 1 |
| 75 |
fi |
| 76 |
- if [[ ! -r "$OPTARG" ]]; then |
| 77 |
+ if [ ! -r "$OPTARG" ]; then |
| 78 |
echo2 "Cannot read keyfile \`$OPTARG': failed" |
| 79 |
exit 1 |
| 80 |
fi |
| 81 |
@@ -144,7 +148,7 @@ |
| 82 |
exit 1 |
| 83 |
fi |
| 84 |
# if there a no key, this will fail |
| 85 |
- if [[ $(gpg --list-keys | wc -l) -eq "0" ]]; then |
| 86 |
+ if [ $(gpg --list-keys | wc -l) -eq "0" ]; then |
| 87 |
echo2 "No gpg keys found" |
| 88 |
exit 1 |
| 89 |
fi |
| 90 |
@@ -163,9 +167,9 @@ |
| 91 |
done |
| 92 |
shift $((OPTIND - 1)) |
| 93 |
|
| 94 |
-if [[ ${1:0:1} == "+" ]]; then |
| 95 |
- DAYS=${1:1} |
| 96 |
- if [[ $DAYS -lt 1 || $DAYS -gt 99 ]]; then |
| 97 |
+if [ "${1%${1#?}}" = "+" ]; then |
| 98 |
+ DAYS=${1#?} |
| 99 |
+ if [ $DAYS -lt 1 ] || [ $DAYS -gt 99 ]; then |
| 100 |
echo2 "+N needs to be a number [1..99]" |
| 101 |
exit 1 |
| 102 |
fi |
| 103 |
@@ -174,7 +178,7 @@ |
| 104 |
DAYS=8 |
| 105 |
fi |
| 106 |
|
| 107 |
-[[ $# -lt 2 ]] && usage && exit |
| 108 |
+[ $# -lt 2 ] && usage && exit |
| 109 |
|
| 110 |
if $mcrypt; then |
| 111 |
if ! which mcrypt 2>/dev/null 1>&2; then |
| 112 |
@@ -184,10 +188,10 @@ |
| 113 |
fi |
| 114 |
|
| 115 |
i=1; last=$#; DIRS= |
| 116 |
-while [[ $i -lt $last ]]; do |
| 117 |
+while [ $i -lt $last ]; do |
| 118 |
DIRS="$DIRS $1" |
| 119 |
shift |
| 120 |
- ((i=$i+1)) |
| 121 |
+ i=$((i+1)) |
| 122 |
done |
| 123 |
# rdup [options] source destination |
| 124 |
#dest="ssh://elektron.atoom.net/directory" |
| 125 |
@@ -197,44 +201,44 @@ |
| 126 |
#dest="ssh://miekg@elektron.atoom.net/directory" |
| 127 |
|
| 128 |
dest=$1 |
| 129 |
-if [[ ${dest:0:6} == "ssh://" ]]; then |
| 130 |
- rest=${dest/ssh:\/\//} |
| 131 |
+if [ "${dest%${dest#??????}}" = "ssh://" ]; then |
| 132 |
+ rest=${dest#ssh://} |
| 133 |
u=${rest%%@*} |
| 134 |
- rest=${rest/$u@/} |
| 135 |
+ rest=${rest#$u@} |
| 136 |
h=`echo $rest | cut -s -f1 -d/` |
| 137 |
- BACKUPDIR=${rest/$h/} |
| 138 |
+ BACKUPDIR=${rest#$h} |
| 139 |
|
| 140 |
- if [[ -z $u ]]; then |
| 141 |
+ if [ -z "$u" ]; then |
| 142 |
ssh=" ssh -c blowfish -x $h" |
| 143 |
else |
| 144 |
ssh=" ssh -c blowfish -x $u@$h" |
| 145 |
fi |
| 146 |
fi |
| 147 |
-if [[ ${dest:0:7} == "file://" ]]; then |
| 148 |
- rest=${dest/file:\/\//} |
| 149 |
+if [ "${dest%${dest#???????}}" = "file://" ]; then |
| 150 |
+ rest=${dest#file://} |
| 151 |
BACKUPDIR=$rest |
| 152 |
fi |
| 153 |
-[[ ${dest:0:1} == "/" ]] && BACKUPDIR=$dest |
| 154 |
+[ "${dest%${dest#?}}" = "/" ] && BACKUPDIR=$dest |
| 155 |
|
| 156 |
# no hits above, assume relative filename |
| 157 |
-[[ -z $BACKUPDIR ]] && BACKUPDIR=$PWD/$dest |
| 158 |
+[ -z "$BACKUPDIR" ] && BACKUPDIR=$PWD/$dest |
| 159 |
|
| 160 |
$link && copy_and_link $DAYS $BACKUPDIR |
| 161 |
|
| 162 |
# change all / to _ to make a valid filename |
| 163 |
-STAMP=$etc/timestamp.${HOSTNAME}.${dest//\//_} |
| 164 |
-LIST=$etc/list.${HOSTNAME}.${dest//\//_} |
| 165 |
+STAMP=$etc/timestamp.${HOSTNAME}.`echo $dest | tr / _` |
| 166 |
+LIST=$etc/list.${HOSTNAME}.`echo $dest | tr / _` |
| 167 |
|
| 168 |
-[[ ! -d $etc ]] && mkdir $etc |
| 169 |
+[ ! -d $etc ] && mkdir $etc |
| 170 |
|
| 171 |
# remote or not |
| 172 |
-if [[ -z $ssh ]]; then |
| 173 |
+if [ -z "$ssh" ]; then |
| 174 |
pipe="rdup-up$OPT $STRIP -t $BACKUPDIR/$NOW" |
| 175 |
else |
| 176 |
pipe="$ssh rdup-up$OPT $STRIP -t $BACKUPDIR/$NOW" |
| 177 |
fi |
| 178 |
# path encryption |
| 179 |
-if [[ -n $pathtrans ]]; then |
| 180 |
+if [ -n "$pathtrans" ]; then |
| 181 |
pipe="rdup-tr $pathtrans | $pipe" |
| 182 |
fi |
| 183 |
|
| 184 |
@@ -242,7 +246,7 @@ |
| 185 |
|
| 186 |
if ! $force; then |
| 187 |
# path is set at the top |
| 188 |
- if [[ -z $ssh ]]; then |
| 189 |
+ if [ -z "$ssh" ]; then |
| 190 |
$PROGNAME -L +$DAYS /dev/null $BACKUPDIR |
| 191 |
# rdup-ln -l $DAYS $BACKUPDIR |
| 192 |
purpose=$? |
| 193 |
@@ -269,5 +273,5 @@ |
| 194 |
if $dry; then |
| 195 |
echo "${cmd}" |
| 196 |
else |
| 197 |
- eval ${cmd} |
| 198 |
+ eval "${cmd}" |
| 199 |
fi |