From efcd98845f1e6888ebcd6a55c70206c517b234aa Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 28 Jun 2007 13:21:41 +0000 Subject: version 0.9. New subcommands: list and package --- Makefile | 2 +- lbu | 148 +++++++++++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 108 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index 5466e4b..e3174aa 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -V=0.8 +V=0.9 P=alpine-conf PV=$(P)-$(V) APKF=$(PV).apk diff --git a/lbu b/lbu index 96da259..2217469 100644 --- a/lbu +++ b/lbu @@ -9,7 +9,7 @@ PREFIX= # this one is from apk-tools . $PREFIX/lib/apk/libutil.sh -VERSION=0.8 +VERSION=0.9 [ "$SFIC" ] && SFIC="$SFIC -i d" # globals @@ -33,6 +33,8 @@ Available subcommands: commit (ci) exclude (ex, delete) include (inc, add) + list (ls) + package (pkg) status (stat, st) update (up) @@ -102,8 +104,10 @@ list_delete() { # usage_include() { echo "$PROGRAM $VERSION -usage: $PROGRAM include [-rv] ... - $PROGRAM include [-v] -l +Add filename(s) to include list (/etc/lbu/include) + +usage: $PROGRAM include|inc|add [-rv] ... + $PROGRAM include|inc|add [-v] -l Options: -l List contents of include list. @@ -136,13 +140,95 @@ show_include() { fi } +# +# lbu_package - create a package +# +usage_package() { + echo "$PROGRAM $VERSION +Create backup package. + +usage: $PROGRAM package|pkg -v [|] + +Options: + -v Verbose mode. + +If is a directory, a package named .apkovl.tar.gz will +be created in the specified directory. + +If is specified, and is not a direcotry, a package with the +specified name willbe created. + +If nor is not specified, a package named +.apkovl.tar.gz will be created in current work directory. +" + exit 1 +} + +cmd_package() { + local pkg="$1" + local rc=0 + local owd="$PWD" + + # find filename + if [ -d "$pkg" ] ; then + pkg="$pkg/$(hostname).apkovl.tar.gz" + elif [ -z "$pkg" ]; then + pkg="$PWD/$(hostname).apkovl.tar.gz" + fi + + # generate the packages.list + cd "$ROOT" + mkdir -p /etc/lbu + echo "#This file is generated by 'lbu package'" > /etc/lbu/packages.list + for i in $(apk_glob '*') ; do + reqby=$(apk_info -qr $i); + # only add the packages who has no REQUIRED_BY + [ -z "$reqby" ] && echo $i + done | sed 's/-[0-9].*//' >> /etc/lbu/packages.list + + # Automatically add list and modified files + currentlist=`VERBOSE="" USE_DEFAULT="-a" cmd_status -a | grep -v ^D | awk '{print $2}'` + + # we generate a tmpcurrent before we commit to avoid race condition + rm -f "$CURRENT_TDB" + $SFIC --add "$CURRENT_TDB" $currentlist + + # create tar archive + [ -f "$EXCLUDE_LIST" ] && excl="-X $EXCLUDE_LIST" + [ -f "$INCLUDE_LIST" ] && incl="-T $INCLUDE_LIST" + if ! tar $VERBOSE $excl $incl -c $currentlist | gzip -c >"$pkg" ; then + rm -f "$CURRENT_TDB" + rc=1 + fi + cd "$owd" + return $rc +} + +# +# lbu list - list files that would go to archive +# +usage_list() { + echo "$PROGRAM $VERSION +Lists files that would go to tar package. Same as: 'lbu package -v /dev/null' + +usage: $PROGRAM list|ls +" + exit 1 +} + +cmd_list() { + VERBOSE="-v" + cmd_package /dev/null +} # # lbu_commit - commit config files to writeable media # usage_commit() { echo "$PROGRAM $VERSION -usage: $PROGRAM commit [-nv] [] +Create a backup of config to writeable media. + +usage: $PROGRAM commit|ci [-nv] [] Options: -n Don't commit, just show what would have been commited. @@ -158,6 +244,7 @@ cmd_commit() { local media mnt was_mounted statuslist tmplist currentlist local incl excl outfile + # find what media to use if [ "$1" ] ; then media="$1" else @@ -165,54 +252,28 @@ cmd_commit() { fi [ -z "$media" ] && usage_commit + # mount media unles its already mounted mnt=/media/$media - [ -d $mnt ] || usage was_mounted=`grep $mnt /proc/mounts` - - cd "$ROOT" - -# # for upgrading from packages.list times -# mkdir -p $(dirname "$INCLUDE_LIST") -# if ! grep "var/lib/apk/world" "$INCLUDE_LIST" >/dev/null 2>&1 ; then -# echo "var/lib/apk/world" >> "$INCLUDE_LIST" -# fi - - # generate the packages.list - mkdir -p /etc/lbu - echo "#This file is generated by 'lbu commit'" > /etc/lbu/packages.list - for i in $(apk_glob '*') ; do - reqby=$(apk_info -qr $i); - # only add the packages who has no REQUIRED_BY - [ -z "$reqby" ] && echo $i - done | sed 's/-[0-9].*//' >> /etc/lbu/packages.list - - # Automatically add list and modified files - currentlist=`VERBOSE="" USE_DEFAULT="-a" cmd_status -a | grep -v ^D | awk '{print $2}'` - if [ -z "$was_mounted" ]; then mount $mnt || die "failed to mount $mnt." fi - # we generate a tmpcurrent before we commit to avoid race condition - [ -f "$CURRENT_TDB" ] || $SFIC --add "$CURRENT_TDB" $currentlist - # commit files to archive if [ "$DRYRUN" ] ; then outfile=/dev/null VERBOSE="-v" else - outfile="$mnt/`hostname`.apkovl.tar.gz" + outfile="$mnt/$(hostname).apkovl.tar.gz" fi - - [ -f "$EXCLUDE_LIST" ] && excl="-X $EXCLUDE_LIST" - [ -f "$INCLUDE_LIST" ] && incl="-T $INCLUDE_LIST" - - if ! tar $VERBOSE $excl $incl -c $currentlist | gzip -c >"$outfile" ; then + + # create package + if ! cmd_package "$outfile"; then + [ -n "$was_mounted" ] && umount "$mnt" rm -f "$CURRENT_TDB" - [ -z "$was_mounted" ] && umount $mnt die "Problems creating archive. aborting" - fi + fi # remove obsolete file if [ -z "$DRYRUN" ] && [ -f $mnt/packages.list ]; then @@ -221,6 +282,7 @@ cmd_commit() { rm -f $mnt/packages.list fi + # make sure data is written and unmount the media sync sleep 1 [ -z "$was_mounted" ] && umount $mnt @@ -234,8 +296,10 @@ cmd_commit() { usage_exclude() { echo "$PROGRAM $VERSION -usage: $PROGRAM exclude [-rv] ... - $PROGRAM exclude [-v] -l +Add filename(s) to exclude list (/etc/lbu/exclude) + +usage: $PROGRAM exclude|ex|delete [-rv] ... + $PROGRAM exclude|ex|delete [-v] -l Options: -l List contents of exclude list. @@ -274,7 +338,7 @@ usage_status() { echo "$PROGRAM $VERSION Check what files have been changed since last commit. -usage: $PROGRAM status [-M ] [-av] +usage: $PROGRAM status|st [-M ] [-av] Options: -M Use a different mask for comparing. (see sfic -h) @@ -320,7 +384,7 @@ usage_update() { echo "$PROGRAM $VERSION Update the commited database without commit to media. -usage: $PROGRAM update [-v] ... +usage: $PROGRAM update|up [-v] ... Options: -v Verbose mode. @@ -352,6 +416,8 @@ case "$cmd" in include|inc|add) SUBCMD="include";; commit|ci) SUBCMD="commit";; exclude|ex|delete) SUBCMD="exclude";; + list|ls) SUBCMD="list";; + package|pkg) SUBCMD="package";; status|stat|st) SUBCMD="status";; update|up) SUBCMD="update";; *) usage;; -- cgit v1.2.3