mirror of
https://github.com/erenfro/gen2stage4.git
synced 2024-11-21 22:25:35 -05:00
Add -i option to include files prior to exclusion (#30)
This commit is contained in:
parent
6de6e25de1
commit
8c61bd4395
2 changed files with 61 additions and 4 deletions
18
mkstage4.sh
18
mkstage4.sh
|
@ -12,6 +12,7 @@ EXCLUDE_CONFIDENTIAL=0
|
|||
EXCLUDE_LOST=0
|
||||
QUIET=0
|
||||
USER_EXCL=()
|
||||
USER_INCL=()
|
||||
S_KERNEL=0
|
||||
PARALLEL=0
|
||||
HAS_PORTAGEQ=0
|
||||
|
@ -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)
|
||||
|
@ -62,6 +64,9 @@ do
|
|||
e)
|
||||
USER_EXCL+=("--exclude=${OPTARG}")
|
||||
;;
|
||||
i)
|
||||
USER_INCL+=("${OPTARG}")
|
||||
;;
|
||||
p)
|
||||
PARALLEL=1
|
||||
;;
|
||||
|
@ -156,6 +161,11 @@ EXCLUDES_DEFAULT_PORTAGE=(
|
|||
|
||||
EXCLUDES+=("${USER_EXCL[@]}")
|
||||
|
||||
INCLUDES=(
|
||||
)
|
||||
|
||||
INCLUDES+=("${USER_INCL[@]}")
|
||||
|
||||
if [ "$TARGET" == '/' ]
|
||||
then
|
||||
EXCLUDES+=("--exclude=$(realpath "$STAGE4_FILENAME")")
|
||||
|
@ -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
|
||||
|
@ -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)"
|
||||
|
|
47
tests/0008.bats
Normal file
47
tests/0008.bats
Normal file
|
@ -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
|
Loading…
Reference in a new issue