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