tazusb diff tazusb @ rev 181

tazusb: extend to "tazusb writefs [compression] [path]"
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sun Aug 09 02:56:14 2015 +0300 (2015-08-09)
parents 8ddffadf56a6
children a0169f6c39b6
line diff
     1.1 --- a/tazusb	Sat Aug 01 22:49:04 2015 +0300
     1.2 +++ b/tazusb	Sun Aug 09 02:56:14 2015 +0300
     1.3 @@ -13,7 +13,7 @@
     1.4  
     1.5  . /lib/libtaz.sh
     1.6  
     1.7 -# Export package name for gettext.
     1.8 +# i18n
     1.9  export TEXTDOMAIN='tazusb'
    1.10  
    1.11  COMMAND="$1"
    1.12 @@ -102,21 +102,6 @@
    1.13  }
    1.14  
    1.15  
    1.16 -# Format target device and label partition.
    1.17 -
    1.18 -mkfs_ext3() {
    1.19 -	_n 'Please specify a label for the partition (TazUSB): '
    1.20 -	read label
    1.21 -
    1.22 -	[ -z "$label" ] && label='TazUSB'
    1.23 -
    1.24 -	_ 'Label: %s' "$label"
    1.25 -	echo "Mkfs: mkfs.ext3 -L \"$label\" $DEVICE"
    1.26 -	newline; sleep 2
    1.27 -	mkfs.ext3 -L "$label" $DEVICE
    1.28 -}
    1.29 -
    1.30 -
    1.31  # Get label for device
    1.32  
    1.33  get_label() {
    1.34 @@ -126,6 +111,18 @@
    1.35  }
    1.36  
    1.37  
    1.38 +# Format target device and label partition.
    1.39 +
    1.40 +mkfs_ext3() {
    1.41 +	get_label
    1.42 +
    1.43 +	_ 'Label: %s' "$label"
    1.44 +	echo "Mkfs: mkfs.ext3 -L \"$label\" $DEVICE"
    1.45 +	newline; sleep 2
    1.46 +	mkfs.ext3 -L "$label" $DEVICE
    1.47 +}
    1.48 +
    1.49 +
    1.50  # Get fs type. Supported fs are ext3, ext2, fat32
    1.51  
    1.52  get_fs_type() {
    1.53 @@ -370,9 +367,8 @@
    1.54  # will activate it, useful for low memory systems
    1.55  
    1.56  gen_swap_file() {
    1.57 -	newline
    1.58 -	boldify "$(_n 'Gen swap')"
    1.59 -	separator
    1.60 +	title "$(_n 'Gen swap')"
    1.61 +
    1.62  	longline "$(_ "Generate a swap file in %s that will be activated on each \
    1.63  boot to have more memory available (empty value to exit)." '/home/swap')"
    1.64  	newline
    1.65 @@ -399,9 +395,8 @@
    1.66  # Clean out old backups to save disk space
    1.67  
    1.68  clean_usb() {
    1.69 -	newline
    1.70 -	boldify "$(_n 'Clean')"
    1.71 -	separator
    1.72 +	title "$(_n 'Clean')"
    1.73 +
    1.74  	longline "$(_n 'Remove old %s backup filesystems to free up disk space.' \
    1.75  'rootfs.gz.unixtimestamp')"
    1.76  	newline
    1.77 @@ -429,19 +424,22 @@
    1.78  	writefs)
    1.79  		# Writefs to rootfs.gz
    1.80  		check_root
    1.81 -		if [ -z "$2" ]; then
    1.82 -			COMPRESSION='none'
    1.83 -		else
    1.84 -			COMPRESSION="$2"
    1.85 -		fi
    1.86 +		# Compression type (optional): lzma, gzip, none. Default is none
    1.87 +		COMPRESSION="${2:-none}"
    1.88 +		# Full path to rootfs.gz (optional). Default is /rootfs.gz
    1.89 +		ROOTFS_PATH="${3:-/rootfs.gz}"
    1.90 +		# File name
    1.91 +		ROOTFS="$(basename "$ROOTFS_PATH")"
    1.92 +
    1.93  		# Start info
    1.94  		title 'Write filesystem'
    1.95  
    1.96  		longline "$(_ "The command writefs will write all the current \
    1.97  filesystem into a suitable cpio archive (%s) usable on a bootable \
    1.98 -LiveUSB media." 'rootfs.gz')"
    1.99 +LiveUSB media." "$ROOTFS")"
   1.100  		newline
   1.101  		_ 'Archive compression: %s' "$(colorize 36 "$COMPRESSION")"
   1.102 +		newline
   1.103  
   1.104  		# Clear out tazpkg cache
   1.105  		rm /var/lib/tazpkg/*.bak /var/cache/tazpkg/* -r -f
   1.106 @@ -449,8 +447,8 @@
   1.107  		# Optionally remove sound card selection and screen resolution.
   1.108  		_ 'Do you wish to remove the sound card and screen configs?'
   1.109  		_n 'Press ENTER to keep or answer (No|yes|exit): '
   1.110 -		read anser
   1.111 -		case $anser in
   1.112 +		read answer
   1.113 +		case $answer in
   1.114  			e|E|"exit"|Exit)
   1.115  				exit 0 ;;
   1.116  			y|Y|yes|Yes)
   1.117 @@ -467,8 +465,8 @@
   1.118  		# Optionally remove i18n settings
   1.119  		_ 'Do you wish to remove local/keymap settings?'
   1.120  		_n 'Press ENTER to keep or answer (No|yes|exit): '
   1.121 -		read anser
   1.122 -		case $anser in
   1.123 +		read answer
   1.124 +		case $answer in
   1.125  			e|E|"exit"|Exit)
   1.126  				exit 0 ;;
   1.127  			y|Y|yes|Yes)
   1.128 @@ -481,6 +479,7 @@
   1.129  				sed  -i  's/^INCLUDE i18n.cfg/# &/' /home/boot/*linux/*linux.c* ;;
   1.130  		esac
   1.131  		status
   1.132 +		newline
   1.133  
   1.134  		# Clean-up files by default
   1.135  		mv -f /var/log/wtmp /tmp/tazusb-wtmp
   1.136 @@ -508,37 +507,40 @@
   1.137  		done
   1.138  
   1.139  		# Generate initramfs with specified compression
   1.140 -		if [ "$COMPRESSION" == 'lzma' ]; then
   1.141 -			_n 'Creating %s with lzma compression... ' 'rootfs.gz'
   1.142 -			cpio -o -H newc | lzma e -si -so > /rootfs.gz
   1.143 -
   1.144 -		elif [ "$COMPRESSION" == 'gzip' ]; then
   1.145 -			_n 'Creating %s with gzip compression... ' 'rootfs.gz'
   1.146 -			cpio -o -H newc | gzip -9 > /rootfs.gz
   1.147 -
   1.148 -		else
   1.149 -			_n 'Creating %s without compression... ' 'rootfs.gz'
   1.150 -			cpio -o -H newc > /rootfs.gz
   1.151 -		fi < /tmp/list
   1.152 +		case "$COMPRESSION" in
   1.153 +			lzma)
   1.154 +				_n 'Creating %s with lzma compression... ' "$ROOTFS"
   1.155 +				cpio -o -H newc | lzma e -si -so > "$ROOTFS_PATH"
   1.156 +				;;
   1.157 +			gzip)
   1.158 +				_n 'Creating %s with gzip compression... ' "$ROOTFS"
   1.159 +				cpio -o -H newc | gzip -9 > "$ROOTFS_PATH"
   1.160 +				;;
   1.161 +			*)
   1.162 +				_n 'Creating %s without compression... ' "$ROOTFS"
   1.163 +				cpio -o -H newc > "$ROOTFS_PATH"
   1.164 +				;;
   1.165 +		esac < /tmp/list
   1.166  
   1.167  		mv -f /tmp/tazusb-wtmp /var/log/wtmp
   1.168  
   1.169  		# Get initramfs size
   1.170 -		size=$(du -sh /rootfs.gz | cut -f1)
   1.171 +		size=$(du -sh "$ROOTFS_PATH" | cut -f1)
   1.172  
   1.173  		# If the bootable medium is where it should be, copy across
   1.174 -		if (test -e /home/boot/bzImage); then
   1.175 -			longline "$(_ 'Moving %s to media. Remember to unmount for delayed writes!' 'rootfs.gz')"
   1.176 +		if [ -e /home/boot/bzImage ]; then
   1.177 +			longline "$(_ 'Moving %s to media. Remember to unmount for delayed writes!' "$ROOTFS")"
   1.178  
   1.179  			# Move the old filesystem with the unix timestamp for reference
   1.180 -			if (test -e /home/boot/previous.gz); then
   1.181 +			if [ -e /home/boot/previous.gz ]; then
   1.182  				mv /home/boot/previous.gz /home/boot/rootfs.gz.$(date +%s)
   1.183  			fi
   1.184  			
   1.185  			mv /home/boot/rootfs.gz /home/boot/previous.gz
   1.186 -			mv /rootfs.gz /home/boot/.
   1.187 +			mv "$ROOTFS_PATH" /home/boot/rootfs.gz
   1.188 +			_ '%s is located in %s' 'rootfs.gz' '/home/boot'
   1.189  		else
   1.190 -			_ '%s is located in /' 'rootfs.gz'
   1.191 +			_ '%s is located in %s' "$ROOTFS" "$(dirname "$ROOTFS_PATH")"
   1.192  		fi
   1.193  
   1.194  		separator