From b75b9f7715ae8e89f7d54c4b8043c06a37cfb6cc Mon Sep 17 00:00:00 2001 From: liu-kan Date: Sat, 15 Dec 2018 04:53:19 +0800 Subject: [PATCH] Try to compress parallelly (#15) * Add -p flag for parallel compressing. The script will test if pbzip2 is install, before using it for parallel compressing. * Update README.md * Update README.md --- README.md | 10 +++++++++- mkstage4.sh | 27 ++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8d92df4..c6bbee7 100644 --- a/README.md +++ b/README.md @@ -43,11 +43,12 @@ mkstage4 -t /custom/mount/point archive_name Command line arguments: ``` - mkstage4.sh [-q -c -b -l -k] [-s || -t ] [-e ] [custom-tar-options] + mkstage4.sh [-q -c -b -l -k -p] [-s || -t ] [-e ] [custom-tar-options] -q: activates quiet mode (no confirmation). -c: excludes connman network lists. -b: excludes boot directory. -l: excludes lost+found directory. + -p: compresses parallelly using pbzip2. -e: an additional excludes directory (one dir one -e). -s: makes tarball of current system. -k: separately save current kernel modules and src (smaller & save decompression time). @@ -70,10 +71,17 @@ tar xvjpf archive_name.tar.bz2.kmod tar xvjpf archive_name.tar.bz2.ksrc ``` +If you have install pbzip2, you can extract parallelly with: +```bash +tar -I pbzip2 -xvf archive_name.tar.bz2 +``` + ## Dependencies * **[Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell))** - in [Portage](http://en.wikipedia.org/wiki/Portage_(software)) as **app-shells/bash** * **[tar](https://en.wikipedia.org/wiki/Tar_(computing))** - in Portage as **app-arch/tar** +* **[pbzip2](https://launchpad.net/pbzip2)** (optional,if it's installed archive can be compressed parallelly) - in Portage as +**app-arch/pbzip2** *Please note that these are very basic dependencies and should already be included in any Linux system.* diff --git a/mkstage4.sh b/mkstage4.sh index c5127da..3567464 100755 --- a/mkstage4.sh +++ b/mkstage4.sh @@ -15,16 +15,18 @@ QUIET=0 USER_EXCL="" S_KERNEL=0 x86_64=0 +PARALLEL=0 if [ `getconf LONG_BIT` = "64" ] then x86_64=1 fi USAGE="usage:\n\ - `basename $0` [-q -c -b -l -k] [-s || -t ] [-e ] [custom-tar-options]\n\ + `basename $0` [-q -c -b -l -k -p] [-s || -t ] [-e ] [custom-tar-options]\n\ -q: activates quiet mode (no confirmation).\n\ -c: excludes 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\ -s: makes tarball of current system.\n\ -k: separately save current kernel modules and src (smaller & save decompression time).\n\ @@ -32,7 +34,7 @@ USAGE="usage:\n\ -h: displays help message." # reads options: -while getopts ':te:skqcblh' flag; do +while getopts ':te:skqcblph' flag; do case "${flag}" in t) TARGET="$OPTARG" @@ -56,8 +58,11 @@ while getopts ':te:skqcblh' flag; do EXCLUDE_LOST=1 ;; e) - USER_EXCL+=" --exclude=${OPTARG}" - ;; + USER_EXCL+=" --exclude=${OPTARG}" + ;; + p) + PARALLEL=1 + ;; h) echo -e "$USAGE" exit 0 @@ -168,7 +173,19 @@ then fi # Generic tar options: -TAR_OPTIONS="-cjpP --ignore-failed-read --xattrs-include='*.*' --numeric-owner" +TAR_OPTIONS="-cpP --ignore-failed-read --xattrs-include='*.*' --numeric-owner" + +if [ ${PARALLEL} -eq 1 ] +then + if hash pbzip2 2>/dev/null; then + TAR_OPTIONS+=" --use-compress-prog=pbzip2" + else + echo "WARING: pbzip2 isn't installed, single-threaded compressing is used." + TAR_OPTIONS+=" -j" + fi +else + TAR_OPTIONS+=" -j" +fi # if not in quiet mode, this message will be displayed: if [ "$AGREE" != "yes" ]