Commit efcd9884 authored by Natanael Copa's avatar Natanael Copa

version 0.9. New subcommands: list and package

parent 3703392b
V=0.8 V=0.9
P=alpine-conf P=alpine-conf
PV=$(P)-$(V) PV=$(P)-$(V)
APKF=$(PV).apk APKF=$(PV).apk
......
...@@ -9,7 +9,7 @@ PREFIX= ...@@ -9,7 +9,7 @@ PREFIX=
# this one is from apk-tools # this one is from apk-tools
. $PREFIX/lib/apk/libutil.sh . $PREFIX/lib/apk/libutil.sh
VERSION=0.8 VERSION=0.9
[ "$SFIC" ] && SFIC="$SFIC -i d" [ "$SFIC" ] && SFIC="$SFIC -i d"
# globals # globals
...@@ -33,6 +33,8 @@ Available subcommands: ...@@ -33,6 +33,8 @@ Available subcommands:
commit (ci) commit (ci)
exclude (ex, delete) exclude (ex, delete)
include (inc, add) include (inc, add)
list (ls)
package (pkg)
status (stat, st) status (stat, st)
update (up) update (up)
...@@ -102,8 +104,10 @@ list_delete() { ...@@ -102,8 +104,10 @@ list_delete() {
# #
usage_include() { usage_include() {
echo "$PROGRAM $VERSION echo "$PROGRAM $VERSION
usage: $PROGRAM include [-rv] <file> ... Add filename(s) to include list (/etc/lbu/include)
$PROGRAM include [-v] -l
usage: $PROGRAM include|inc|add [-rv] <file> ...
$PROGRAM include|inc|add [-v] -l
Options: Options:
-l List contents of include list. -l List contents of include list.
...@@ -136,13 +140,95 @@ show_include() { ...@@ -136,13 +140,95 @@ show_include() {
fi fi
} }
#
# lbu_package - create a package
#
usage_package() {
echo "$PROGRAM $VERSION
Create backup package.
usage: $PROGRAM package|pkg -v [<dirname>|<filename>]
Options:
-v Verbose mode.
If <dirname> is a directory, a package named <hostname>.apkovl.tar.gz will
be created in the specified directory.
If <filename> is specified, and is not a direcotry, a package with the
specified name willbe created.
If <dirname> nor <filename> is not specified, a package named
<hostname>.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 # lbu_commit - commit config files to writeable media
# #
usage_commit() { usage_commit() {
echo "$PROGRAM $VERSION echo "$PROGRAM $VERSION
usage: $PROGRAM commit [-nv] [<media>] Create a backup of config to writeable media.
usage: $PROGRAM commit|ci [-nv] [<media>]
Options: Options:
-n Don't commit, just show what would have been commited. -n Don't commit, just show what would have been commited.
...@@ -158,6 +244,7 @@ cmd_commit() { ...@@ -158,6 +244,7 @@ cmd_commit() {
local media mnt was_mounted statuslist tmplist currentlist local media mnt was_mounted statuslist tmplist currentlist
local incl excl outfile local incl excl outfile
# find what media to use
if [ "$1" ] ; then if [ "$1" ] ; then
media="$1" media="$1"
else else
...@@ -165,54 +252,28 @@ cmd_commit() { ...@@ -165,54 +252,28 @@ cmd_commit() {
fi fi
[ -z "$media" ] && usage_commit [ -z "$media" ] && usage_commit
# mount media unles its already mounted
mnt=/media/$media mnt=/media/$media
[ -d $mnt ] || usage [ -d $mnt ] || usage
was_mounted=`grep $mnt /proc/mounts` 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 if [ -z "$was_mounted" ]; then
mount $mnt || die "failed to mount $mnt." mount $mnt || die "failed to mount $mnt."
fi fi
# we generate a tmpcurrent before we commit to avoid race condition
[ -f "$CURRENT_TDB" ] || $SFIC --add "$CURRENT_TDB" $currentlist
# commit files to archive # commit files to archive
if [ "$DRYRUN" ] ; then if [ "$DRYRUN" ] ; then
outfile=/dev/null outfile=/dev/null
VERBOSE="-v" VERBOSE="-v"
else else
outfile="$mnt/`hostname`.apkovl.tar.gz" outfile="$mnt/$(hostname).apkovl.tar.gz"
fi fi
[ -f "$EXCLUDE_LIST" ] && excl="-X $EXCLUDE_LIST" # create package
[ -f "$INCLUDE_LIST" ] && incl="-T $INCLUDE_LIST" if ! cmd_package "$outfile"; then
[ -n "$was_mounted" ] && umount "$mnt"
if ! tar $VERBOSE $excl $incl -c $currentlist | gzip -c >"$outfile" ; then
rm -f "$CURRENT_TDB" rm -f "$CURRENT_TDB"
[ -z "$was_mounted" ] && umount $mnt
die "Problems creating archive. aborting" die "Problems creating archive. aborting"
fi fi
# remove obsolete file # remove obsolete file
if [ -z "$DRYRUN" ] && [ -f $mnt/packages.list ]; then if [ -z "$DRYRUN" ] && [ -f $mnt/packages.list ]; then
...@@ -221,6 +282,7 @@ cmd_commit() { ...@@ -221,6 +282,7 @@ cmd_commit() {
rm -f $mnt/packages.list rm -f $mnt/packages.list
fi fi
# make sure data is written and unmount the media
sync sync
sleep 1 sleep 1
[ -z "$was_mounted" ] && umount $mnt [ -z "$was_mounted" ] && umount $mnt
...@@ -234,8 +296,10 @@ cmd_commit() { ...@@ -234,8 +296,10 @@ cmd_commit() {
usage_exclude() { usage_exclude() {
echo "$PROGRAM $VERSION echo "$PROGRAM $VERSION
usage: $PROGRAM exclude [-rv] <file> ... Add filename(s) to exclude list (/etc/lbu/exclude)
$PROGRAM exclude [-v] -l
usage: $PROGRAM exclude|ex|delete [-rv] <file> ...
$PROGRAM exclude|ex|delete [-v] -l
Options: Options:
-l List contents of exclude list. -l List contents of exclude list.
...@@ -274,7 +338,7 @@ usage_status() { ...@@ -274,7 +338,7 @@ usage_status() {
echo "$PROGRAM $VERSION echo "$PROGRAM $VERSION
Check what files have been changed since last commit. Check what files have been changed since last commit.
usage: $PROGRAM status [-M <MASK>] [-av] usage: $PROGRAM status|st [-M <MASK>] [-av]
Options: Options:
-M Use a different mask for comparing. (see sfic -h) -M Use a different mask for comparing. (see sfic -h)
...@@ -320,7 +384,7 @@ usage_update() { ...@@ -320,7 +384,7 @@ usage_update() {
echo "$PROGRAM $VERSION echo "$PROGRAM $VERSION
Update the commited database without commit to media. Update the commited database without commit to media.
usage: $PROGRAM update [-v] <file> ... usage: $PROGRAM update|up [-v] <file> ...
Options: Options:
-v Verbose mode. -v Verbose mode.
...@@ -352,6 +416,8 @@ case "$cmd" in ...@@ -352,6 +416,8 @@ case "$cmd" in
include|inc|add) SUBCMD="include";; include|inc|add) SUBCMD="include";;
commit|ci) SUBCMD="commit";; commit|ci) SUBCMD="commit";;
exclude|ex|delete) SUBCMD="exclude";; exclude|ex|delete) SUBCMD="exclude";;
list|ls) SUBCMD="list";;
package|pkg) SUBCMD="package";;
status|stat|st) SUBCMD="status";; status|stat|st) SUBCMD="status";;
update|up) SUBCMD="update";; update|up) SUBCMD="update";;
*) usage;; *) usage;;
......
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