mysql: No longer prepend vroot to the backupdir.
[matthijs/upstream/backupninja-vserver.git] / lib / tools.in
index fe7d54a38de94fc8c7b44513e402e227314021d8..4ca438f05e8dc17fc7d44537e66145609a0d1dc4 100644 (file)
@@ -89,3 +89,19 @@ function interpolate() {
        # Do the actual interpolation
        echo $path | sed "$expr"
 }
+
+# Does the $1 start with $2 ?
+function starts_with() {
+       # Get the head of $1 as long as $2
+       head=`echo $1 | head -c ${#2}`
+       # Is it equal to $2?
+       [ "$head" = "$2" ]
+}
+
+# Strip the prefix $2 from $1. Assumes that $1 actually starts with $1.
+# The result is put on stdout.
+function strip_prefix() {
+       # Strip the first ${#2} (the length of $2) characters from $1.
+       # tail -c +N means start at the Nth byte, 1-based, so we add 1.
+       echo $1 | tail -c +$((${#2}+1))
+}