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
PV=$(P)-$(V)
APKF=$(PV).apk
......
......@@ -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] <file> ...
$PROGRAM include [-v] -l
Add filename(s) to include list (/etc/lbu/include)
usage: $PROGRAM include|inc|add [-rv] <file> ...
$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 [<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
#
usage_commit() {
echo "$PROGRAM $VERSION
usage: $PROGRAM commit [-nv] [<media>]
Create a backup of config to writeable media.
usage: $PROGRAM commit|ci [-nv] [<media>]
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] <file> ...
$PROGRAM exclude [-v] -l
Add filename(s) to exclude list (/etc/lbu/exclude)
usage: $PROGRAM exclude|ex|delete [-rv] <file> ...
$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 <MASK>] [-av]
usage: $PROGRAM status|st [-M <MASK>] [-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] <file> ...
usage: $PROGRAM update|up [-v] <file> ...
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;;
......
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