Commit 56e001fb authored by Natanael Copa's avatar Natanael Copa

lbu: make lbu commit work with apk-tools-2.x

parent b7662b83
...@@ -4,31 +4,18 @@ ...@@ -4,31 +4,18 @@
# Copyright (c) 2006 Natanael Copa # Copyright (c) 2006 Natanael Copa
# May be distributed under GPL2 # May be distributed under GPL2
PREFIX=
. $PREFIX/lib/libalpine.sh
# this one is from apk-tools
. $PREFIX/lib/apk/libutil.sh
VERSION=1.2 VERSION=1.2
[ "$SFIC" ] && SFIC="$SFIC -i d"
# globals if [ ! -f ${libalpine:="./libalpine.sh"} ]; then
[ -z "$LBU_DBDIR" ] && LBU_DBDIR="${APK_DATA:-$ROOT/var/lib/apk}" libalpine=/usr/share/lbu/libalpine.sh
CURRENT_TDB="$LBU_DBDIR/current.tdb" fi
TMPCURRENT_TDB="$LBU_DBDIR/tmp-current.tdb" . $libalpine || exit 1
COMMITED_TDB="$LBU_DBDIR/commited.tdb"
EXCLUDE_LIST=/etc/lbu/exclude EXCLUDE_LIST=/etc/lbu/exclude
INCLUDE_LIST=/etc/lbu/include INCLUDE_LIST=/etc/lbu/include
PACKAGES_LIST=/etc/lbu/packages.list
DEFAULT_CIPHER="aes-256-cbc" DEFAULT_CIPHER="aes-256-cbc"
MASK="Npugsh"
LBUDIRS=`echo "$APK_LBUDIRS" | sed 's/:/ /g'`
LBU_CONF=/etc/lbu/lbu.conf LBU_CONF=/etc/lbu/lbu.conf
if [ -f "$LBU_CONF" ]; then if [ -f "$LBU_CONF" ]; then
. "$LBU_CONF" . "$LBU_CONF"
...@@ -47,7 +34,6 @@ Available subcommands: ...@@ -47,7 +34,6 @@ Available subcommands:
list (ls) list (ls)
package (pkg) package (pkg)
status (stat, st) status (stat, st)
update (up)
list-backup (lb) list-backup (lb)
revert revert
...@@ -61,8 +47,6 @@ Common options: ...@@ -61,8 +47,6 @@ Common options:
cleanup() { cleanup() {
local i local i
rm -f "$CURRENT_TDB"
rm -f "$TMPCURRENT_TDB"
for i in $UMOUNT_LIST; do for i in $UMOUNT_LIST; do
umount $i umount $i
done done
...@@ -99,14 +83,6 @@ check_openssl() { ...@@ -99,14 +83,6 @@ check_openssl() {
|| die "Cipher $ENCRYPTION is not supported" || die "Cipher $ENCRYPTION is not supported"
} }
gen_current_tdb() {
# generate current tdb
rm -f "$CURRENT_TDB"
mkdir -p "$(dirname \"$CURRENT_TDB\")"
$SFIC -R -t --mask "$MASK" --old "$APK_DEFAULT_TDB" $LBUDIRS \
| grep -v ^D | awk '{print $2}' | $SFIC --add "$CURRENT_TDB" --file -
}
# list_add(char *listfile, char* file...) # list_add(char *listfile, char* file...)
list_add() { list_add() {
local list="$1" local list="$1"
...@@ -228,24 +204,8 @@ cmd_package() { ...@@ -228,24 +204,8 @@ cmd_package() {
tmppkg="$tmpdir/$(basename $pkg)" tmppkg="$tmpdir/$(basename $pkg)"
# generate the packages.list cd "${ROOT:-/}"
vecho "Generating $PACKAGES_LIST" currentlist=$(apk audit --backup -q)
cd "$ROOT"
mkdir -p $(dirname $PACKAGES_LIST)
echo "#This file is generated by 'lbu package' (lbu $VERSION)" \
> $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].*//' >> $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 # create tar archive
[ -f "$EXCLUDE_LIST" ] && excl="-X $EXCLUDE_LIST" [ -f "$EXCLUDE_LIST" ] && excl="-X $EXCLUDE_LIST"
...@@ -281,8 +241,6 @@ cmd_package() { ...@@ -281,8 +241,6 @@ cmd_package() {
fi fi
fi fi
vecho "Created $pkg" vecho "Created $pkg"
else
rm -f "$CURRENT_TDB"
fi fi
return $rc return $rc
} }
...@@ -414,7 +372,6 @@ cmd_commit() { ...@@ -414,7 +372,6 @@ cmd_commit() {
[ "$media" = "floppy" ] && sleep 1 [ "$media" = "floppy" ] && sleep 1
# move current to commited. # move current to commited.
[ "$DRYRUN" ] || mv "$CURRENT_TDB" "$COMMITED_TDB"
vecho "Successfully saved apk overlay files" vecho "Successfully saved apk overlay files"
} }
...@@ -460,7 +417,7 @@ show_exclude() { ...@@ -460,7 +417,7 @@ show_exclude() {
} }
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# lbu_status - check what files have been changed since last save # lbu_listbackup - Show old commits
usage_listbackup() { usage_listbackup() {
cat <<EOF cat <<EOF
$PROGRAM $VERSION $PROGRAM $VERSION
...@@ -518,68 +475,16 @@ usage_status() { ...@@ -518,68 +475,16 @@ 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|st [-M <MASK>] [-av] usage: $PROGRAM status|st [-av]
Options: Options:
-M Use a different mask for comparing. (see sfic -h)
-a Compare all files, not just since last commit. -a Compare all files, not just since last commit.
-v Also show include and exclude lists. -v Also show include and exclude lists.
" "
exit 1 exit 1
} }
cmd_status() {
cd "$ROOT"
[ "$SFIC" ] || die "Need sfic."
[ -f "$APK_DEFAULT_TDB" ] || die "$APK_DEFAULT_TDB not found."
# genereate temp tdb
#gen_temp_tdb
if [ -f "$COMMITED_TDB" ] && [ -z "$USE_DEFAULT" ]; then
# generate current tdb
gen_current_tdb
OLD="$COMMITED_TDB"
NEW="--new $CURRENT_TDB"
else
OLD="$APK_DEFAULT_TDB"
NEW="-R $LBUDIRS"
fi
$SFIC $QUIET $VERBOSE --mask "$MASK" -t --old "$OLD" $NEW
local retcode=$?
if [ "$VERBOSE" ] ; then
echo ""
show_include
echo ""
show_exclude
fi
return $retcode
}
#------------------------------------------------
# lbu_update - Update the database wihtout commit to media.
usage_update() {
echo "$PROGRAM $VERSION
Update the commited database without commit to media.
usage: $PROGRAM update|up [-v] <file> ...
Options:
-v Verbose mode.
"
exit 1
}
cmd_update() {
[ $# -lt 1 ] && usage_update
cd "$ROOT"
for i in "$@" ; do
echo $i | sed 's:^/::'
done | lbu_filter | $SFIC $VERBOSE --add "$COMMITED_TDB" --file -
}
#----------------------------------------------------------- #-----------------------------------------------------------
# Main # Main
...@@ -600,7 +505,6 @@ case "$cmd" in ...@@ -600,7 +505,6 @@ case "$cmd" in
list|ls) SUBCMD="list";; list|ls) SUBCMD="list";;
package|pkg) SUBCMD="package";; package|pkg) SUBCMD="package";;
status|stat|st) SUBCMD="status";; status|stat|st) SUBCMD="status";;
update|up) SUBCMD="update";;
list-backup|lb) SUBCMD="listbackup";; list-backup|lb) SUBCMD="listbackup";;
revert) SUBCMD="revert";; revert) SUBCMD="revert";;
*) usage;; *) usage;;
...@@ -620,9 +524,6 @@ while getopts "adehlM:np:qrv" opt ; do ...@@ -620,9 +524,6 @@ while getopts "adehlM:np:qrv" opt ; do
;; ;;
l) LIST="-l" l) LIST="-l"
;; ;;
M) [ $SUBCMD = status ] || usage_$SUBCMD
MASK="$OPTARG"
;;
n) [ $SUBCMD = commit ] || usage_$SUBCMD n) [ $SUBCMD = commit ] || usage_$SUBCMD
DRYRUN="-n" DRYRUN="-n"
;; ;;
......
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