Commit 4e857d18 authored by Natanael Copa's avatar Natanael Copa

lbu: use apk's protected_path.d instead of tar include/exclude

parent d4174d86
...@@ -17,6 +17,8 @@ fi ...@@ -17,6 +17,8 @@ fi
EXCLUDE_LIST="$sysconfdir"/exclude EXCLUDE_LIST="$sysconfdir"/exclude
INCLUDE_LIST="$sysconfdir"/include INCLUDE_LIST="$sysconfdir"/include
LBU_LIST="/etc/apk/protected_paths.d/lbu.list"
DEFAULT_CIPHER="aes-256-cbc" DEFAULT_CIPHER="aes-256-cbc"
...@@ -123,35 +125,57 @@ check_openssl() { ...@@ -123,35 +125,57 @@ check_openssl() {
|| die "Cipher $ENCRYPTION is not supported" || die "Cipher $ENCRYPTION is not supported"
} }
# list_add(char *listfile, char* file...) # grep and sed has issues with escaping '*' in lists so we rather do
# our own filter functions
list_has() {
local line=
while read line; do
[ "$line" = "$1" ] && return 0
done < "$LBU_LIST"
return 1
}
list_filter_out() {
local line=
while read line; do
if [ "$line" != "$1" ]; then
echo "$line"
fi
done < "$LBU_LIST"
}
# list_add(char prefix, char *listfile, char* file...)
list_add() { list_add() {
local list="$1" local prefix="$1"
shift shift
mkdir -p `dirname "$list"` mkdir -p "${LBU_LIST%/*}"
while [ $# -gt 0 ] ; do while [ $# -gt 0 ] ; do
filename=`echo "$1" | sed 's:^/\+::'` filename="$(echo "$1" | sed 's:^/\+::')"
if grep "^$filename$" "$list" >/dev/null 2>&1 ; then if list_has "${prefix}${filename}"; then
vecho "$filename is already in $list." vecho "$filename is already in $LBU_LIST."
else else
vecho "Adding $filename to $list." vecho "Adding $filename to $LBU_LIST."
echo "$filename" >> "$list" echo "${prefix}${filename}" >> "$LBU_LIST"
fi fi
shift shift
done done
} }
# list_delete(char *listfile, char *file...) # list_delete(char prefix, char *listfile, char *file...)
list_delete() { list_delete() {
local list="$1" local prefix="$1"
local tmp="$list.old" local tmp="$LBU_LIST.new"
shift shift
[ -f "$list" ] || return 1 [ -f "$LBU_LIST" ] || return 1
while [ $# -gt 0 ] ; do while [ $# -gt 0 ] ; do
filename=`echo "$1" | sed 's:^/\+::'` filename="$(echo "$1" | sed 's:^/\+::')"
mv "$list" "$tmp" if list_has "${prefix}${filename}"; then
vecho "Removing $filename from list." vecho "Removing $filename from $LBU_LIST."
grep -v "^$filename$" "$tmp" > "$list" list_filter_out "${prefix}${filename}" > "$tmp" \
rm "$tmp" && mv "$tmp" "$LBU_LIST"
else
vecho "$filename is not in $LBU_LIST"
fi
shift shift
done done
} }
...@@ -213,17 +237,17 @@ cmd_include() { ...@@ -213,17 +237,17 @@ cmd_include() {
[ $# -lt 1 ] && usage_include [ $# -lt 1 ] && usage_include
if [ "$REMOVE" ] ; then if [ "$REMOVE" ] ; then
list_delete "$INCLUDE_LIST" "$@" list_delete + "$@"
else else
list_add "$INCLUDE_LIST" "$@" list_add + "$@"
list_delete "$EXCLUDE_LIST" "$@" list_delete - "$@"
fi fi
} }
show_include() { show_include() {
if [ -f "$INCLUDE_LIST" ] ; then if [ -f "$LBU_LIST" ] ; then
vecho "Include files:" vecho "Include files:"
cat "$INCLUDE_LIST" grep -- '^+' "$LBU_LIST" | sed 's/^+//'
fi fi
} }
...@@ -252,7 +276,7 @@ If <dirname> nor <filename> is not specified, a package named ...@@ -252,7 +276,7 @@ If <dirname> nor <filename> is not specified, a package named
} }
_gen_filelist() { _gen_filelist() {
apk audit --backup -q apk audit --backup --quiet --recursive
if [ -f var/lib/apk/world ]; then if [ -f var/lib/apk/world ]; then
echo var/lib/apk/world echo var/lib/apk/world
fi fi
...@@ -267,7 +291,7 @@ cmd_package() { ...@@ -267,7 +291,7 @@ cmd_package() {
local rc=0 local rc=0
local owd="$PWD" local owd="$PWD"
local suff="apkovl.tar.gz" local suff="apkovl.tar.gz"
local tmpdir tmppkg tmpexclude tmpinclude local tmpdir tmppkg
check_openssl check_openssl
init_tmpdir tmpdir init_tmpdir tmpdir
...@@ -286,8 +310,8 @@ cmd_package() { ...@@ -286,8 +310,8 @@ cmd_package() {
fi fi
tmppkg="$tmpdir/$(basename $pkg)" tmppkg="$tmpdir/$(basename $pkg)"
tmpexclude="$tmpdir"/exclude
tmpinclude="$tmpdir"/include local tar_create="tar -c --no-recursion"
cd "${ROOT:-/}" cd "${ROOT:-/}"
# remove old package.list # remove old package.list
...@@ -297,32 +321,22 @@ cmd_package() { ...@@ -297,32 +321,22 @@ cmd_package() {
rm -f etc/lbu/packages.list rm -f etc/lbu/packages.list
fi fi
# create tar archive # create tar archive
if [ -f "$EXCLUDE_LIST" ]; then
# strip empty lines and lines with only whitespace
sed -e '/^[[:space:]]*$/d' "$EXCLUDE_LIST" > $tmpexclude
excl="-X $tmpexclude"
fi
if [ -f "$INCLUDE_LIST" ]; then
# strip empty lines and lines with only whitespace
sed -e '/^[[:space:]]*$/d' "$INCLUDE_LIST" > $tmpinclude
incl="-T $tmpinclude"
fi
if [ -n "$VERBOSE" ]; then if [ -n "$VERBOSE" ]; then
echo "Archiving the following files:" >&2 echo "Archiving the following files:" >&2
# we dont want to mess the tar output with the # we dont want to mess the tar output with the
# password prompt. Lets get the tar output first. # password prompt. Lets get the tar output first.
_gen_filelist_0 | xargs -0 tar $excl $incl -c -v > /dev/null _gen_filelist_0 | xargs -0 $tar_create -v > /dev/null
rc=$? rc=$?
fi fi
if [ $rc -eq 0 ]; then if [ $rc -eq 0 ]; then
if [ -z "$ENCRYPTION" ]; then if [ -z "$ENCRYPTION" ]; then
_gen_filelist_0 | xargs -0 tar $excl $incl -c \ _gen_filelist_0 | xargs -0 $tar_create \
| gzip -c >"$tmppkg" | gzip -c >"$tmppkg"
rc=$? rc=$?
else else
set -- enc "-$ENCRYPTION" -salt set -- enc "-$ENCRYPTION" -salt
[ -n "$PASSWORD" ] && set -- "$@" -pass pass:"$PASSWORD" [ -n "$PASSWORD" ] && set -- "$@" -pass pass:"$PASSWORD"
_gen_filelist_0 | xargs -0 tar $excl $incl -c \ _gen_filelist_0 | xargs -0 $tar_create \
| gzip -c \ | gzip -c \
| $OPENSSL "$@" > "$tmppkg" | $OPENSSL "$@" > "$tmppkg"
rc=$? rc=$?
...@@ -518,17 +532,17 @@ cmd_exclude() { ...@@ -518,17 +532,17 @@ cmd_exclude() {
[ $# -lt 1 ] && usage_exclude [ $# -lt 1 ] && usage_exclude
if [ "$REMOVE" ] ; then if [ "$REMOVE" ] ; then
list_delete "$EXCLUDE_LIST" "$@" list_delete - "$@"
else else
list_delete "$INCLUDE_LIST" "$@" list_delete + "$@"
list_add "$EXCLUDE_LIST" "$@" list_add - "$@"
fi fi
} }
show_exclude() { show_exclude() {
if [ -f "$EXCLUDE_LIST" ] ; then if [ -f "$LBU_LIST" ] ; then
vecho "Exclude files:" vecho "Exclude files:"
cat "$EXCLUDE_LIST" grep -- '^-' "$LBU_LIST" | sed 's/^-//'
fi fi
} }
......
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