2014-05-18 17:52:33 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# checks if run as root:
|
|
|
|
if ! [ "`whoami`" == "root" ]
|
|
|
|
then
|
|
|
|
echo "`basename $0`: must be root."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-05-20 03:07:01 -04:00
|
|
|
#set flag variables to null
|
|
|
|
EXCLUDE_BOOT=0
|
|
|
|
EXCLUDE_CONNMAN=0
|
2016-02-18 00:45:51 -05:00
|
|
|
EXCLUDE_LOST=1
|
2014-05-20 03:07:01 -04:00
|
|
|
QUIET=0
|
2016-02-11 01:51:15 -05:00
|
|
|
USAGE="usage:\n\
|
|
|
|
`basename $0` [-q -c -b] [-s || -t <target-mountpoint>] <archive-filename> [custom-tar-options]\n\
|
|
|
|
-q: activates quiet mode (no confirmation).\n\
|
|
|
|
-c: excludes connman network lists.\n\
|
|
|
|
-b: excludes boot directory.\n\
|
2016-02-18 00:45:51 -05:00
|
|
|
-l: includes lost+found directory.\n\
|
2016-02-11 01:51:15 -05:00
|
|
|
-s: makes tarball of current system.\n\
|
|
|
|
-t: makes tarball of system located at the <target-mountpoint>.\n\
|
|
|
|
-h: displays help message."
|
2014-05-20 03:07:01 -04:00
|
|
|
|
2014-05-18 17:52:33 -04:00
|
|
|
# reads options:
|
2016-02-18 00:45:51 -05:00
|
|
|
while getopts ':t:sqcblh' flag; do
|
2014-05-18 17:52:33 -04:00
|
|
|
case "${flag}" in
|
|
|
|
t)
|
|
|
|
TARGET="$OPTARG"
|
|
|
|
;;
|
|
|
|
s)
|
|
|
|
TARGET="/"
|
|
|
|
;;
|
|
|
|
q)
|
|
|
|
QUIET=1
|
|
|
|
;;
|
|
|
|
c)
|
|
|
|
EXCLUDE_CONNMAN=1
|
|
|
|
;;
|
|
|
|
b)
|
|
|
|
EXCLUDE_BOOT=1
|
|
|
|
;;
|
2016-02-18 00:45:51 -05:00
|
|
|
l)
|
|
|
|
EXCLUDE_LOST=0
|
|
|
|
;;
|
2016-02-11 01:51:15 -05:00
|
|
|
h)
|
|
|
|
echo -e "$USAGE"
|
|
|
|
exit 0
|
|
|
|
;;
|
2014-05-18 17:52:33 -04:00
|
|
|
\?)
|
|
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
:)
|
|
|
|
echo "Option -$OPTARG requires an argument." >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2016-02-11 01:45:57 -05:00
|
|
|
if [ "$TARGET" == "" ]
|
|
|
|
then
|
|
|
|
echo "`basename $0`: no target specified."
|
2016-02-11 01:51:15 -05:00
|
|
|
echo -e "$USAGE"
|
2016-02-11 01:45:57 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-05-18 17:52:33 -04:00
|
|
|
# shifts pointer to read mandatory output file specification
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
ARCHIVE=$1
|
|
|
|
|
|
|
|
# checks for correct output file specification
|
|
|
|
if [ "$ARCHIVE" == "" ]
|
|
|
|
then
|
|
|
|
echo "`basename $0`: no archive file name specified."
|
2016-02-11 01:51:15 -05:00
|
|
|
echo -e "$USAGE"
|
2014-05-18 17:52:33 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# checks for quiet mode (no confirmation)
|
|
|
|
if [ ${QUIET} -eq 1 ]
|
|
|
|
then
|
|
|
|
AGREE="yes"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# determines if filename was given with relative or absolute path
|
2016-01-26 18:16:58 -05:00
|
|
|
if [ "`echo $ARCHIVE | grep -c '^\/'`" -gt "0" ]
|
2014-05-18 17:52:33 -04:00
|
|
|
then
|
|
|
|
STAGE4_FILENAME="${ARCHIVE}.tar.bz2"
|
|
|
|
else
|
|
|
|
STAGE4_FILENAME="`pwd`/${ARCHIVE}.tar.bz2"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#Shifts pointer to read custom tar options
|
|
|
|
shift;OPTIONS="$@"
|
|
|
|
|
|
|
|
# Excludes:
|
|
|
|
EXCLUDES="\
|
2016-01-26 18:15:40 -05:00
|
|
|
--exclude=.bash_history \
|
|
|
|
--exclude=dev/* \
|
|
|
|
--exclude=media/* \
|
|
|
|
--exclude=mnt/*/* \
|
2014-05-20 03:07:01 -04:00
|
|
|
--exclude=proc/* \
|
2016-01-26 18:15:40 -05:00
|
|
|
--exclude=run/* \
|
2014-05-20 03:07:01 -04:00
|
|
|
--exclude=sys/* \
|
|
|
|
--exclude=tmp/* \
|
2016-01-26 18:15:40 -05:00
|
|
|
--exclude=usr/portage/* \
|
2014-05-20 03:07:01 -04:00
|
|
|
--exclude=var/lock/* \
|
|
|
|
--exclude=var/log/* \
|
2016-01-26 18:15:40 -05:00
|
|
|
--exclude=var/run/*"
|
2014-05-18 17:52:33 -04:00
|
|
|
|
|
|
|
if [ "$TARGET" == "/" ]
|
|
|
|
then
|
2016-01-26 17:49:29 -05:00
|
|
|
EXCLUDES+=" --exclude=${STAGE4_FILENAME#/}"
|
2014-05-18 17:52:33 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${EXCLUDE_CONNMAN} -eq 1 ]
|
|
|
|
then
|
2014-05-20 03:08:59 -04:00
|
|
|
EXCLUDES+=" --exclude=var/lib/connman/*"
|
2014-05-18 17:52:33 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${EXCLUDE_BOOT} -eq 1 ]
|
|
|
|
then
|
2016-02-11 01:39:12 -05:00
|
|
|
EXCLUDES+=" --exclude=boot/*"
|
2014-05-18 17:52:33 -04:00
|
|
|
fi
|
|
|
|
|
2016-02-18 00:45:51 -05:00
|
|
|
if [ ${EXCLUDE_LOST} -eq 1 ]
|
|
|
|
then
|
|
|
|
EXCLUDES+=" --exclude=lost+found"
|
|
|
|
fi
|
|
|
|
|
2014-05-18 17:52:33 -04:00
|
|
|
# Generic tar options:
|
|
|
|
TAR_OPTIONS="-cjpP --ignore-failed-read -f"
|
|
|
|
|
|
|
|
# if not in quiet mode, this message will be displayed:
|
|
|
|
if [ "$AGREE" != "yes" ]
|
|
|
|
then
|
|
|
|
echo "Are you sure that you want to make a stage 4 tarball of the system"
|
2014-05-20 19:21:51 -04:00
|
|
|
echo "located under the following directory?"
|
|
|
|
echo "$TARGET"
|
2014-05-18 17:52:33 -04:00
|
|
|
echo ""
|
|
|
|
echo "WARNING: since all data is saved by default the user should exclude all"
|
2014-05-20 03:07:01 -04:00
|
|
|
echo "security- or privacy-related files and directories, which are not"
|
|
|
|
echo "already excluded by mkstage4 options (such as -c), manually per cmdline."
|
2014-05-18 17:52:33 -04:00
|
|
|
echo "example: \$ `basename $0` -s /my-backup --exclude=/etc/ssh/ssh_host*"
|
|
|
|
echo ""
|
2016-02-11 01:55:30 -05:00
|
|
|
echo "COMMAND LINE PREVIEW:"
|
2014-05-20 03:07:01 -04:00
|
|
|
echo "cd $TARGET && tar $TAR_OPTIONS $STAGE4_FILENAME * $EXCLUDES $OPTIONS"
|
2014-05-18 17:52:33 -04:00
|
|
|
echo ""
|
|
|
|
echo -n "Type \"yes\" to continue or anything else to quit: "
|
|
|
|
read AGREE
|
|
|
|
fi
|
|
|
|
|
|
|
|
# start stage4 creation:
|
|
|
|
if [ "$AGREE" == "yes" ]
|
|
|
|
then
|
2014-05-20 03:07:01 -04:00
|
|
|
cd $TARGET && tar $TAR_OPTIONS $STAGE4_FILENAME * $EXCLUDES $OPTIONS
|
2014-05-18 17:52:33 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|