summaryrefslogtreecommitdiff
path: root/sysutils/rdup/files/patch-rdup-simple
blob: 30e5e097de16fec7e1c47277acfaec1c10d0c768 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
--- rdup-simple.orig	2010-06-21 05:17:06.000000000 -0700
+++ rdup-simple		2010-06-27 17:05:46.000000000 -0700
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # updates a hardlinked backup
 # licensed under the GPL version 3
@@ -38,16 +38,17 @@
 	exit 2
     fi
 
-    let i=1
+    i=1
     while [ $i -le $LOOKBACK ]; do
-	    D=$(date $DATESTR --date "$i days ago")
+	    adjust=$(printf %dd $i)
+	    D=$(date -v-$adjust $DATESTR)
 	    if [ -d $TOPDIR/$D ]; then
-		if ! cp -plr $TOPDIR/$D/* $TOPDIR/$TODAY; then
+		if ! cp -plR $TOPDIR/$D/* $TOPDIR/$TODAY; then
 		    exit 2
 		fi
 		exit 0
 	    fi
-	    let i=i+1
+	    i=$((i+1))
     done
     exit 1
 }
@@ -121,7 +122,7 @@
                         exit 1
                 fi
                 if [ ! -r "$OPTARG" ]; then
-                        echo2 "Cannot read keyfile \`$OPTARG': failed"
+                        echo2 "Cannot read keyfile \'$OPTARG': failed"
                         exit 1
                 fi
                 trans="$trans -Pmcrypt,-q,-f,$OPTARG"
@@ -163,9 +164,9 @@
 done
 shift $((OPTIND - 1))
 
-if [ "${1:0:1}" = "+" ]; then
-        DAYS=${1:1}
-	if [ $DAYS -lt 1 ] || [ $DAYS -gt 99 ]; then
+if [ "${1%${1#?}}" = "+" ]; then
+        DAYS=${1#?}
+        if [ $DAYS -lt 1 ] || [ $DAYS -gt 99 ]; then
                 echo2 "+N needs to be a number [1..99]"
                 exit 1
         fi
@@ -187,7 +188,7 @@
 while [ $i -lt $last ]; do
 	DIRS="$DIRS $1"
 	shift
-	((i=$i+1))
+	i=$((i+1))
 done
 # rdup [options] source destination
 #dest="ssh://elektron.atoom.net/directory"
@@ -197,8 +198,8 @@
 #dest="ssh://miekg@elektron.atoom.net/directory"
 
 dest=$1
-if [ ${dest:0:6} = "ssh://" ]; then
-	rest=${dest/ssh:\/\//}
+if [ "${dest%${dest#??????}}" = "ssh://" ]; then
+	rest=${dest#ssh://}
 	u=${rest%%@*}
 
 	if [ "$u" = "$rest" ]; then
@@ -206,9 +207,9 @@
             u=
         fi
 
-	rest=${rest/$u@/}
+	rest=${rest#$u@}
 	h=$(echo $rest | cut -s -f1 -d/)
-	BACKUPDIR=${rest/$h/}
+	BACKUPDIR=${rest#$h}
 
 	if [ -z "$u" ]; then
 		ssh=" ssh -c blowfish -x $h"
@@ -216,11 +217,11 @@
 		ssh=" ssh -c blowfish -x $u@$h"
 	fi
 fi
-if [ ${dest:0:7} = "file://" ]; then
-	rest=${dest/file:\/\//}
+if [ "${dest%${dest#???????}}" = "file://" ]; then
+	rest=${dest#file://}
 	BACKUPDIR=$rest
 fi
-[ ${dest:0:1} = "/" ] && BACKUPDIR=$dest
+[ "${dest%${dest#?}}" = "/" ] && BACKUPDIR=$dest
 
 # no hits above, assume relative filename
 [ -z "$BACKUPDIR" ] && BACKUPDIR=$PWD/$dest
@@ -228,8 +229,8 @@
 $link && copy_and_link $DAYS $BACKUPDIR
 
 # change all / to _ to make a valid filename
-STAMP=$etc/timestamp.${HOSTNAME}.${dest//\//_}
-LIST=$etc/list.${HOSTNAME}.${dest//\//_}
+STAMP=$etc/timestamp.${HOSTNAME}.$(echo $dest | tr / _)
+LIST=$etc/list.${HOSTNAME}.$(echo $dest | tr / _)
 
 [ ! -d $etc ] && mkdir $etc
 
@@ -250,6 +251,7 @@
 	# path is set at the top
         if [ -z "$ssh" ]; then
 		$PROGNAME $OPT_DRY -L +$DAYS /dev/null $BACKUPDIR
+#		rdup-ln -l $DAYS $BACKUPDIR
                 purpose=$?
         else
 		# You need to set your path so rdup-simple can be found