Skip to content

Commit

Permalink
Add -i option to include files prior to exclusion (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianposton authored Apr 3, 2020
1 parent 6de6e25 commit 8c61bd4
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
18 changes: 14 additions & 4 deletions mkstage4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ EXCLUDE_CONFIDENTIAL=0
EXCLUDE_LOST=0
QUIET=0
USER_EXCL=()
USER_INCL=()
S_KERNEL=0
PARALLEL=0
HAS_PORTAGEQ=0
Expand All @@ -22,20 +23,21 @@ then
fi

USAGE="usage:\n\
$(basename "$0") [-q -c -b -l -k -p] [-s || -t <target-mountpoint>] [-e <additional excludes dir*>] <archive-filename> [custom-tar-options]\n\
$(basename "$0") [-q -c -b -l -k -p] [-s || -t <target-mountpoint>] [-e <additional excludes dir*>] [-i <additional include target>] <archive-filename> [custom-tar-options]\n\
-q: activates quiet mode (no confirmation).\n\
-c: excludes some confidential files (currently only .bash_history and connman network lists).\n\
-b: excludes boot directory.\n\
-l: excludes lost+found directory.\n\
-p: compresses parallelly using pbzip2.\n\
-e: an additional excludes directory (one dir one -e, donot use it with *).\n\
-i: an additional target to include. This has higher precedence than -e, -t, and -s.\n\
-s: makes tarball of current system.\n\
-k: separately save current kernel modules and src (smaller & save decompression time).\n\
-t: makes tarball of system located at the <target-mountpoint>.\n\
-h: displays help message."

# reads options:
while getopts ":t:e:skqcblph" flag
while getopts ":t:e:i:skqcblph" flag
do
case "$flag" in
t)
Expand All @@ -62,6 +64,9 @@ do
e)
USER_EXCL+=("--exclude=${OPTARG}")
;;
i)
USER_INCL+=("${OPTARG}")
;;
p)
PARALLEL=1
;;
Expand Down Expand Up @@ -156,6 +161,11 @@ EXCLUDES_DEFAULT_PORTAGE=(

EXCLUDES+=("${USER_EXCL[@]}")

INCLUDES=(
)

INCLUDES+=("${USER_INCL[@]}")

if [ "$TARGET" == '/' ]
then
EXCLUDES+=("--exclude=$(realpath "$STAGE4_FILENAME")")
Expand Down Expand Up @@ -215,7 +225,7 @@ then
echo "example: \$ $(basename "$0") -s /my-backup --exclude=/etc/ssh/ssh_host*"
echo
echo "COMMAND LINE PREVIEW:"
echo 'tar' "${TAR_OPTIONS[@]}" "${EXCLUDES[@]}" "${OPTIONS[@]}" -f "$STAGE4_FILENAME" "${TARGET}"
echo 'tar' "${TAR_OPTIONS[@]}" "${INCLUDES[@]}" "${EXCLUDES[@]}" "${OPTIONS[@]}" -f "$STAGE4_FILENAME" "${TARGET}"
if ((S_KERNEL))
then
echo
Expand All @@ -230,7 +240,7 @@ fi
# start stage4 creation:
if [ "$AGREE" == 'yes' ]
then
tar "${TAR_OPTIONS[@]}" "${EXCLUDES[@]}" "${OPTIONS[@]}" -f "$STAGE4_FILENAME" "${TARGET}"
tar "${TAR_OPTIONS[@]}" "${INCLUDES[@]}" "${EXCLUDES[@]}" "${OPTIONS[@]}" -f "$STAGE4_FILENAME" "${TARGET}"
if ((S_KERNEL))
then
tar "${TAR_OPTIONS[@]}" -f "$STAGE4_FILENAME.ksrc" "${TARGET}usr/src/linux-$(uname -r)"
Expand Down
47 changes: 47 additions & 0 deletions tests/0008.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bats

load test_helper

setup() {
f test/home/user/.dotfile
f test/home/user/.keep
f test/etc/ssh/key
f test/etc/ssh/config
f test/boot/boot
f test/boot/kernel
f test/mnt/5/media
mkstage4.sh \
-i 'test/home/user/.keep' \
-e 'user/.*' \
-i 'test/etc/ssh/config' \
-e 'ssh' \
-b \
-i 'test/boot/boot' \
-i 'test/mnt/5' \
-q -t test test
}

teardown() {
rm -rf test test.tar.bz2
}

@test "-i 'test/home/user/.keep and -e 'user/.*'" {
assert_tar_excludes test/home/user/.dotfile
assert_tar_includes test/home/user/.keep
}

@test "-i 'test/etc/ssh/config and -e 'ssh'" {
assert_tar_excludes test/etc/ssh/key
assert_tar_includes test/etc/ssh/config
}

@test "-i 'test/boot/boot' and -b" {
assert_tar_excludes test/boot/kernel
assert_tar_includes test/boot/boot
}

@test "-i 'test/mnt/5'" {
assert_tar_includes test/mnt/5/media
}

# vim: ft=bash

0 comments on commit 8c61bd4

Please sign in to comment.