Commit 7e11b0b7 authored by Natanael Copa's avatar Natanael Copa

lbu log.

trap signals and cleanup.
initial lbu revert.
parent 187bf571
...@@ -33,7 +33,8 @@ if [ -f "$LBU_CONF" ]; then ...@@ -33,7 +33,8 @@ if [ -f "$LBU_CONF" ]; then
. "$LBU_CONF" . "$LBU_CONF"
fi fi
retcode=0 UMOUNT_LIST=
usage() { usage() {
echo "$PROGRAM $VERSION" echo "$PROGRAM $VERSION"
echo "usage: $PROGRAM <subcommand> [options] [args] echo "usage: $PROGRAM <subcommand> [options] [args]
...@@ -46,6 +47,7 @@ Available subcommands: ...@@ -46,6 +47,7 @@ Available subcommands:
package (pkg) package (pkg)
status (stat, st) status (stat, st)
update (up) update (up)
log
Common options: Common options:
-h Show help for subcommand. -h Show help for subcommand.
...@@ -55,6 +57,26 @@ Common options: ...@@ -55,6 +57,26 @@ Common options:
exit 1 exit 1
} }
cleanup() {
local i
rm -f "$CURRENT_TDB"
rm -f "$TMPCURRENT_TDB"
for i in $UMOUNT_LIST; do
umount $i
done
}
exit_clean() {
cleanup
exit 1
}
mount_once() {
if grep $1 /proc/mounts >/dev/null; then
mount $1 && UMOUNT_LIST="$1 $UMOUNT_LIST"
fi
}
# verify we have openssl if we want to encrypt # verify we have openssl if we want to encrypt
check_openssl() { check_openssl() {
[ -z "$ENCRYPTION" ] && return 0 [ -z "$ENCRYPTION" ] && return 0
...@@ -294,7 +316,7 @@ The environment varialbes can also be set in $LBU_CONF ...@@ -294,7 +316,7 @@ The environment varialbes can also be set in $LBU_CONF
} }
cmd_commit() { cmd_commit() {
local media mnt was_mounted statuslist tmplist currentlist local media mnt statuslist tmplist currentlist
local incl excl outfile ovls lines local incl excl outfile ovls lines
check_openssl check_openssl
...@@ -303,20 +325,13 @@ cmd_commit() { ...@@ -303,20 +325,13 @@ cmd_commit() {
[ -n "$DRYRUN" ] && VERBOSE="-v" [ -n "$DRYRUN" ] && VERBOSE="-v"
# find what media to use # find what media to use
if [ "$1" ] ; then media="${1:-$LBU_MEDIA}"
media="$1"
else
media="$LBU_MEDIA"
fi
[ -z "$media" ] && usage_commit [ -z "$media" ] && usage_commit
# mount media unles its already mounted # mount media unles its already mounted
mnt=/media/$media mnt=/media/$media
[ -d "$mnt" ] || usage [ -d "$mnt" ] || usage
was_mounted=`grep $mnt /proc/mounts` mount_once "$mnt" || die "failed to mount $mnt"
if [ -z "$was_mounted" ]; then
mount $mnt || die "failed to mount $mnt."
fi
# find the outfile # find the outfile
outfile="$mnt/$(hostname).apkovl.tar.gz" outfile="$mnt/$(hostname).apkovl.tar.gz"
...@@ -345,7 +360,7 @@ cmd_commit() { ...@@ -345,7 +360,7 @@ cmd_commit() {
[ -z "$DRYRUN" ] && mv "$outfile" "$backup" [ -z "$DRYRUN" ] && mv "$outfile" "$backup"
elif [ -n "$lines" ]; then elif [ -n "$lines" ]; then
# More then one apkovl, this is a security concern # More then one apkovl, this is a security concern
[ -z "$was_mounted" ] && umount "$mnt" cleanup
eecho "The following apkovl file(s) were found:" eecho "The following apkovl file(s) were found:"
eecho "$lines" eecho "$lines"
eecho "" eecho ""
...@@ -355,8 +370,7 @@ cmd_commit() { ...@@ -355,8 +370,7 @@ cmd_commit() {
# create package # create package
if ! cmd_package "$outfile"; then if ! cmd_package "$outfile"; then
[ -n "$was_mounted" ] && umount "$mnt" cleanup
rm -f "$CURRENT_TDB"
die "Problems creating archive. aborting" die "Problems creating archive. aborting"
fi fi
...@@ -378,10 +392,9 @@ cmd_commit() { ...@@ -378,10 +392,9 @@ cmd_commit() {
rm -f $mnt/packages.list rm -f $mnt/packages.list
fi fi
# make sure data is written and unmount the media # make sure data is written
sync sync
sleep 1 [ "$media" = "floppy" ] && sleep 1
[ -z "$was_mounted" ] && umount "$mnt"
# move current to commited. # move current to commited.
[ "$DRYRUN" ] || mv "$CURRENT_TDB" "$COMMITED_TDB" [ "$DRYRUN" ] || mv "$CURRENT_TDB" "$COMMITED_TDB"
...@@ -429,6 +442,39 @@ show_exclude() { ...@@ -429,6 +442,39 @@ show_exclude() {
fi fi
} }
#---------------------------------------------------------------------------
# lbu_status - check what files have been changed since last save
usage_log()
cat <<EOF
$PROGRAM $VERSION
Show old commits.
usage: $PROGRAM log [<media>]
EOF
exit 1
}
cmd_log() {
local media=${1:-"$LBU_MEDIA"}
local mnt="/media/$media"
[ -z "$media" ] && usage_log
mount_once "$mnt" || die "failed to mount $mnt"
ls -1 "$mnt"/*.[0-9][0-9]*[0-9][0-9].tar.gz* 2>/dev/null | sed 's:.*/::'
}
#---------------------------------------------------------------------------
# lbu_revert - revert to old config
usage_revert() {
}
cmd_revert() {
local revertto=$1
local media=${2:-"$LBU_MEDIA"}
}
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# lbu_status - check what files have been changed since last save # lbu_status - check what files have been changed since last save
usage_status() { usage_status() {
...@@ -465,7 +511,7 @@ cmd_status() { ...@@ -465,7 +511,7 @@ cmd_status() {
fi fi
$SFIC $QUIET $VERBOSE --mask "$MASK" -t --old "$OLD" $NEW $SFIC $QUIET $VERBOSE --mask "$MASK" -t --old "$OLD" $NEW
retcode=$? local retcode=$?
if [ "$VERBOSE" ] ; then if [ "$VERBOSE" ] ; then
echo "" echo ""
...@@ -473,6 +519,7 @@ cmd_status() { ...@@ -473,6 +519,7 @@ cmd_status() {
echo "" echo ""
show_exclude show_exclude
fi fi
return $retcode
} }
#------------------------------------------------ #------------------------------------------------
...@@ -552,7 +599,9 @@ while getopts "adehlM:np:qrv" opt ; do ...@@ -552,7 +599,9 @@ while getopts "adehlM:np:qrv" opt ; do
done done
shift `expr $OPTIND - 1` shift `expr $OPTIND - 1`
trap exit_clean SIGINT SIGTERM
cmd_$SUBCMD "$@" cmd_$SUBCMD "$@"
# cleanup retcode=$?
rm -f "$CURRENT_TDB"
cleanup
exit $retcode exit $retcode
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment