Merge pull request #5 from rbaumbach/master
Add getops to script to provide user the ability to skip autoexpanding
This commit is contained in:
commit
abb17e217e
|
@ -1,9 +1,9 @@
|
||||||
# PiShrink #
|
# PiShrink #
|
||||||
PiShrink is a bash script that automatically shrink a pi image that will then resize to the max size of the SD card on boot. This will make putting the image back onto the SD card faster and the shrunk images will compress better.
|
PiShrink is a bash script that automatically shrink a pi image that will then resize to the max size of the SD card on boot. This will make putting the image back onto the SD card faster and the shrunk images will compress better.
|
||||||
|
|
||||||
`Usage: ./pishrink imagefile.img [newimagefile.img]`
|
`Usage: ./pishrink [-s] imagefile.img [newimagefile.img]`
|
||||||
|
|
||||||
If you specify the `newimagefile.img` parameter, the script will make a copy of `imagefile.img` and work off that. You will need enough space to make a full copy of the image to use that option.
|
If the `-s` option is given the script will skip the autoexpanding part of the process. If you specify the `newimagefile.img` parameter, the script will make a copy of `imagefile.img` and work off that. You will need enough space to make a full copy of the image to use that option.
|
||||||
|
|
||||||
## Example ##
|
## Example ##
|
||||||
```bash
|
```bash
|
||||||
|
|
21
pishrink.sh
21
pishrink.sh
|
@ -1,11 +1,23 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
usage() { echo "Usage: $0 [-s] imagefile.img [newimagefile.img]"; exit -1; }
|
||||||
|
|
||||||
|
should_skip_autoexpand=false
|
||||||
|
|
||||||
|
while getopts ":s" opt; do
|
||||||
|
case "${opt}" in
|
||||||
|
s) should_skip_autoexpand=true ;;
|
||||||
|
*) usage ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
#Args
|
#Args
|
||||||
img=$1
|
img=$1
|
||||||
|
|
||||||
#Usage checks
|
#Usage checks
|
||||||
if [[ -z $img ]]; then
|
if [[ -z $img ]]; then
|
||||||
echo "Usage: $0 imagefile.img [newimagefile.img]"
|
usage
|
||||||
exit -1
|
|
||||||
fi
|
fi
|
||||||
if [[ ! -e $img ]]; then
|
if [[ ! -e $img ]]; then
|
||||||
echo "ERROR: $img is not a file..."
|
echo "ERROR: $img is not a file..."
|
||||||
|
@ -42,6 +54,8 @@ loopback=`losetup -f --show -o $partstart $img`
|
||||||
currentsize=`tune2fs -l $loopback | grep 'Block count' | tr -d ' ' | cut -d ':' -f 2 | tr -d '\n'`
|
currentsize=`tune2fs -l $loopback | grep 'Block count' | tr -d ' ' | cut -d ':' -f 2 | tr -d '\n'`
|
||||||
blocksize=`tune2fs -l $loopback | grep 'Block size' | tr -d ' ' | cut -d ':' -f 2 | tr -d '\n'`
|
blocksize=`tune2fs -l $loopback | grep 'Block size' | tr -d ' ' | cut -d ':' -f 2 | tr -d '\n'`
|
||||||
|
|
||||||
|
#Check if we should make pi expand rootfs on next boot
|
||||||
|
if [ "$should_skip_autoexpand" = false ]; then
|
||||||
#Make pi expand rootfs on next boot
|
#Make pi expand rootfs on next boot
|
||||||
mountdir=`mktemp -d`
|
mountdir=`mktemp -d`
|
||||||
mount $loopback $mountdir
|
mount $loopback $mountdir
|
||||||
|
@ -58,6 +72,9 @@ EOF
|
||||||
chmod +x $mountdir/etc/rc.local
|
chmod +x $mountdir/etc/rc.local
|
||||||
fi
|
fi
|
||||||
umount $mountdir
|
umount $mountdir
|
||||||
|
else
|
||||||
|
echo Skipping autoexpanding process...
|
||||||
|
fi
|
||||||
|
|
||||||
#Make sure filesystem is ok
|
#Make sure filesystem is ok
|
||||||
e2fsck -f $loopback
|
e2fsck -f $loopback
|
||||||
|
|
Loading…
Reference in New Issue