summaryrefslogtreecommitdiffstats
path: root/lsinitcpio
diff options
context:
space:
mode:
Diffstat (limited to 'lsinitcpio')
-rwxr-xr-xlsinitcpio109
1 files changed, 53 insertions, 56 deletions
diff --git a/lsinitcpio b/lsinitcpio
index 2dc7d35..f94dd8c 100755
--- a/lsinitcpio
+++ b/lsinitcpio
@@ -5,11 +5,9 @@
shopt -s extglob
-declare verbose=
-declare list='--list'
-declare -i color=1
-declare NC= BOLD= BLUE= GREEN= RED= YELLOW=
-declare FUNCTIONS=functions
+_list='--list'
+_optcolor=1 _optverbose=0
+_f_functions=functions
usage() {
cat<<USAGE
@@ -31,10 +29,10 @@ USAGE
}
decomp() {
- ${compress:-cat} ${compress:+-cd} "$@"
+ ${_compress:-cat} ${_compress:+-cd} "$@"
}
-. "$FUNCTIONS"
+. "$_f_functions"
# override the die method from functions
die() {
@@ -73,19 +71,19 @@ analyze_image() {
# fallback in case tput failed us
columns=${columns:-80}
- zsize=$(stat -c %s "$image")
+ zsize=$(stat -c %s "$_image")
# calculate compression ratio
- TIMEFORMAT=%R decomptime=$({ time decomp "$image" >/dev/null; } 2>&1 )
- if [[ $compress ]]; then
- fullsize=$(decomp "$image" | bsdtar xOf - | wc -c)
+ TIMEFORMAT=%R decomptime=$({ time decomp "$_image" >/dev/null; } 2>&1 )
+ if [[ $_compress ]]; then
+ fullsize=$(decomp "$_image" | bsdtar xOf - | wc -c)
ratio=.$(( zsize * 1000 / fullsize % 1000 ))
fi
# decompress the image since we need to read from it multiple times. we
# have to pass this through decomp() since the image might be lzop which
# bsdtar can't read.
- decomp "$image" | bsdtar -C "$workdir" -xf -
+ decomp "$_image" | bsdtar -C "$workdir" -xf -
# collect stats
kernver=("$workdir"/usr/lib/modules/*/)
@@ -113,15 +111,15 @@ analyze_image() {
explicitmod=($MODULES)
# print results
- imagename=$image
- [[ -L $image ]] && imagename+=" -> $(readlink -e "$image")"
+ imagename=$_image
+ [[ -L $_image ]] && imagename+=" -> $(readlink -e "$_image")"
msg 'Image: %s %s' "$imagename"
[[ $version ]] && msg 'Created with mkinitcpio %s' "$version"
msg 'Kernel: %s' "${kernver:-unknown}"
msg 'Size: %s' "$(size_to_human "$zsize")"
- if [[ $compress ]]; then
- msg 'Compressed with: %s' "$compress"
+ if [[ $_compress ]]; then
+ msg 'Compressed with: %s' "$_compress"
msg2 'Uncompressed size: %s (%s ratio)' "$(size_to_human "$fullsize")" "$ratio"
fi
msg2 'Estimated extraction time: %ss' "$decomptime"
@@ -166,32 +164,32 @@ analyze_image() {
fi
}
-OPT_SHORT='achlnvx'
-OPT_LONG=('analyze' 'help' 'list' 'nocolor' 'showconfig' 'verbose' 'extract')
+_opt_short='achlnvx'
+_opt_long=('analyze' 'help' 'list' 'nocolor' 'showconfig' 'verbose' 'extract')
-if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
+if ! parseopts "$_opt_short" "${_opt_long[@]}" -- "$@"; then
exit 1
fi
set -- "${OPTRET[@]}"
-unset OPT_SHORT OPT_LONG OPTRET
+unset _opt_short _opt_long OPTRET
while :; do
case $1 in
-a|--analyze)
- analyze=1 ;;
+ _optanalyze=1 ;;
-c|--config)
- showconfig=1 ;;
+ _optshowconfig=1 ;;
-h|--help)
usage
exit 0 ;;
-l|--list)
- listcontents=1 ;;
+ _optlistcontents=1 ;;
-n|--nocolor)
- color=0 ;;
+ _optcolor=0 ;;
-v|--verbose)
- verbose='--verbose' ;;
+ _optverbose='--verbose' ;;
-x|--extract)
- unset list ;;
+ unset _list ;;
--)
shift
break 2 ;;
@@ -199,55 +197,54 @@ while :; do
shift
done
-declare image=$1
+_image=$1
-if [[ -t 1 ]] && (( color )); then
+if [[ -t 1 ]] && (( _optcolor )); then
# prefer terminal safe colored and bold text when tput is supported
if tput setaf 0 &>/dev/null; then
- NC="$(tput sgr0)"
- BOLD="$(tput bold)"
- BLUE="$BOLD$(tput setaf 4)"
- GREEN="$BOLD$(tput setaf 2)"
- RED="$BOLD$(tput setaf 1)"
- YELLOW="$BOLD$(tput setaf 3)"
+ _color_none="$(tput sgr0)"
+ _color_bold="$(tput bold)"
+ _color_blue="$_color_bold$(tput setaf 4)"
+ _color_green="$_color_bold$(tput setaf 2)"
+ _color_red="$_color_bold$(tput setaf 1)"
+ _color_yellow="$_color_bold$(tput setaf 3)"
else
- NC="\e[1;0m"
- BOLD="\e[1;1m"
- BLUE="$BOLD\e[1;34m"
- GREEN="$BOLD\e[1;32m"
- RED="$BOLD\e[1;31m"
- YELLOW="$BOLD\e[1;33m"
+ _color_none="\e[1;0m"
+ _color_bold="\e[1;1m"
+ _color_blue="$_color_bold\e[1;34m"
+ _color_green="$_color_bold\e[1;32m"
+ _color_red="$_color_bold\e[1;31m"
+ _color_yellow="$_color_bold\e[1;33m"
fi
fi
-readonly NC BOLD BLUE GREEN RED YELLOW
-[[ $image ]] || die "No image specified (use -h for help)"
-[[ -f $image ]] || die "No such file: $image"
+[[ $_image ]] || die "No image specified (use -h for help)"
+[[ -f $_image ]] || die "No such file: %s" "$_image"
-case $(( analyze + listcontents + showconfig )) in
+case $(( _optanalyze + _optlistcontents + _optshowconfig )) in
0)
# default action when none specified
- listcontents=1 ;;
+ _optlistcontents=1 ;;
[!1])
die "Only one action may be specified at a time" ;;
esac
# read compression type
-case "$(file -Lb "$image")" in
- @(data|LZMA)*) compress=lzma ;;
- gzip*) compress=gzip ;;
- bzip2*) compress=bzip2 ;;
- lzop*) compress=lzop ;;
- XZ*) compress=xz ;;
+case $(file -Lb "$_image") in
+ @(data|LZMA)*) _compress=lzma ;;
+ gzip*) _compress=gzip ;;
+ bzip2*) _compress=bzip2 ;;
+ lzop*) _compress=lzop ;;
+ XZ*) _compress=xz ;;
esac
-if (( analyze )); then
- analyze_image "$image"
-elif (( showconfig )); then
- decomp "$1" | bsdtar xOf - buildconfig 2>/dev/null ||
+if (( _optanalyze )); then
+ analyze_image "$_image"
+elif (( _optshowconfig )); then
+ decomp "$_image" | bsdtar xOf - buildconfig 2>/dev/null ||
die 'Failed to extract config from image (mkinitcpio too old?)'
else
- decomp "$image" | bsdcpio -i --quiet $verbose $list
+ decomp "$_image" | bsdcpio -i --quiet $_optverbose $_list
fi
# vim: set ft=sh ts=4 sw=4 et: