Skip to content

Commit

Permalink
fix bugs to make it work
Browse files Browse the repository at this point in the history
  • Loading branch information
gutenye committed Jan 6, 2014
1 parent 6f72aca commit d6f6d0f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 34 deletions.
18 changes: 18 additions & 0 deletions libexec/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
before() { :; }
after() { :; }

run_as_root() {
if [[ `id -u` -ne 0 ]]; then
echo "oldtime: you cannot perform this operation unless you are root." >&2
exit 1
fi
}

check_mountpoint() {
if ! mountpoint -q "$1"; then
echo "oldtime: \`$1' is unmounted." >&2
exit 1
fi
}

# vim: ft=sh
23 changes: 9 additions & 14 deletions libexec/lib.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
before() { :; }
after() { :; }

run_as_root() {
if [[ `id -u` -ne 0 ]]; then
echo "oldtime: you cannot perform this operation unless you are root." >&2
exit 1
fi
absolutename() {
readlink -f "$1"
}

check_mountpoint() {
if ! mountpoint -q "$1"; then
echo "oldtime: \`$1' is unmounted." >&2
exit 1
fi
filename() {
base=$(basename "$1")
echo ${base%.*}
}

# vim: ft=sh
extname() {
base=$(basename "$1")
[[ "$base" =~ \. ]] && echo "${base##*.}" || echo ""
}
18 changes: 2 additions & 16 deletions libexec/oldtime
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,15 @@
set -e
export -n CDPATH

VERSION="2.0.0"

####
# Lib
####

absolutename() {
readlink -f $1
}

extname() {
[ $1 =~ '\.' ] && echo ${1##*.} || echo ""
}

filename() {
dirname ${1%.*}
}
VERSION="2.0.0"

if [ -n "$OLDTIME_DEBUG" ]; then
export PS4='+ [${BASH_SOURCE##*/}:${LINENO}] '
set -x
fi

absolutename() { readlink -f "$1"; }
bin_path=`dirname $(absolutename "$0")`
OLDTIME_ROOT=`dirname "$bin_path"`
export OLDTIME_ROOT
Expand Down
6 changes: 4 additions & 2 deletions libexec/oldtime-backup
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
set -e
[[ -n "$OLDTIME_DEBUG" ]] && set -x

source "$OLDTIME_ROOT/libexec/lib.sh"
source "$OLDTIME_ROOT/libexec/helpers.sh"

# parse file and write each section to files
# parse_file(file) -> files_cmd "--files-from files"
parse_file() {
Expand Down Expand Up @@ -52,7 +55,7 @@ parse_file() {
invoke_rsync() {
rm -f tmp/*
files_cmd=$(parse_file "$1")
end_cmd=$(sed "1s~\\$SRC~$SRC~;s~\\$DEST~$DEST~;q" "$1")
end_cmd=$(sed "1s~\$SRC~$SRC~;s~\$DEST~$DEST~;q" "$1")
cmd="$files_cmd $BACKUP_OPTIONS $RSYNC_OPTIONS $end_cmd"
echo ">> rsync $cmd"
rsync $cmd
Expand All @@ -71,7 +74,6 @@ brsync() {
invoke_rsync "$file"
}

source "$OLDTIME_ROOT/libexec/lib.sh"

#####
# Main
Expand Down
5 changes: 3 additions & 2 deletions libexec/oldtime-restore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
set -e
[[ -n "$OLDTIME_DEBUG" ]] && set -x

source "$OLDTIME_ROOT/libexec/lib.sh"
source "$OLDTIME_ROOT/libexec/helpers.sh"

invoke_rsync() {
end_cmd=$(sed "1s~\\$SRC~$SRC~;s~\\$DEST~$DEST~;q" "$1")
end_cmd=$(echo $end_cmd | awk '{print $2, $1}')
Expand All @@ -39,8 +42,6 @@ rrsync() {
invoke_rsync "$file"
}

source "$OLDTIME_ROOT/libexec/lib.sh"

#####
# Main
#####
Expand Down

0 comments on commit d6f6d0f

Please sign in to comment.