[
  {
    "path": ".gitattributes",
    "content": "# Auto detect text files and perform LF normalization\n* text=auto\n\n# Custom for Visual Studio\n*.cs     diff=csharp\n\n# Standard to msysgit\n*.doc\t diff=astextplain\n*.DOC\t diff=astextplain\n*.docx diff=astextplain\n*.DOCX diff=astextplain\n*.dot  diff=astextplain\n*.DOT  diff=astextplain\n*.pdf  diff=astextplain\n*.PDF\t diff=astextplain\n*.rtf\t diff=astextplain\n*.RTF\t diff=astextplain\n"
  },
  {
    "path": "README.md",
    "content": "# **shrink**\n\n**Linux bash script to resize Raspberry SD card images**  \nconsider further [remarks](#remarks)\n\n### **new version**\n\\- dependency tests  \n\\- low memory warning  \n\\- argument handling and help screen  \n\\- automated size retrieving from GParted  \n\\- progress bars with ETA for all time consuming actions  \n\\- environment variable support\n\n---\n\n### **download**\ndownload repository from GitHub,  \nunzip and copy for example to: ~/shrink\n\n**or**\n\ncopy script to current directory  \n`wget https://raw.github.com/qrti/shrink/master/script/shrink.sh`\n\n**or**\n\ncheck if git is installed  \n`$ git --version`\n\nif git is not installed  \n`$ sudo apt-get install git-all`\n\nclone shrink repository to current directory  \n`$ git clone https://github.com/qrti/shrink.git`\n\n---\n\n### **necessary installs**\n`$ sudo apt-get install gparted`  \n`$ sudo apt-get install pv`\n\n---\n\n### **prepare**\n**before executing the script the first time, insert your SD card**\n\nenter the following at the command line and find the name of your SD device and partitions  \n`$ df -h`\n\nnow extract the device name\n\nexample 1 for list entries like:  \n/dev/sdb1 + /dev/sdb2\n\nomit digit at the end  \n\nresult:  \n/dev/sdb\n\nexample 2 for list entries like:  \n/dev/mmcblk1p1 + /dev/mmcblk1p2\n\nomit p and digit at the end\n\nresult:  \n/dev/mmcblk1 \n\n**make script executable once**\n\nchange directory  \n`$ cd ~/shrink/script`\n\n`$ chmod 755 shrink.sh`  \n**or**  \n`$ chmod a+x shrink.sh`\n\n---\n\n### **execute**\n**usage and help**\n\n```\nUsage:\n  (sudo) shrink.sh [<arguments>]\n  (sudo) shrink.sh -h | --help\n  (sudo) shrink.sh\n```\n\nexamples:  \n`$ sudo ./shrink.sh`  \nread, resize and zero fill image\n\n`$ sudo ./shrink.sh --compress --skip-fill`  \nread, resize and compress image without zero fill\n\n`$ sudo ./shrink.sh --device /dev/mmcblk1`  \nread, resize and zero fill image from device /dev/mmcblk1\n\nthe help screen shows options and their current default values\n\n```\nOptions:\n  -h --help             show this screen\n  --user                specify user who should own output files (default: root)\n  --device              source and target SD card device (default: /dev/sdb)\n  --date_name           image name, alternative with date and time: \"image_191003113547 (default: image)\"\n  --image               image name with extension (default: image.img)\n  --details             gparted details file path and name (default: ~/gparted_details.htm)\n  --compress            compress new image (an extra file is generated) (default: false)\n  --write               write new image to SD card (default: false)\n  --skip-read           read image from SD card (false for an already existing image) (default: true)\n  --skip-resize         resize image with GParted (default: true)\n  --skip-fill           fill empty space of new image with zeroes, only possible if RESIZE=true (default: true)\n```\n\n**changing default values by editing the script**  \n`$ nano shrink.sh`\n\nexample for:  \n/dev/sdb1 + /dev/sdb2  \nomit digit\n```\nDEVICE=${DEVICE:-/dev/sdb}\n```\n\nexample for:  \n/dev/mmcblk1p1 + /dev/mmcblk1p2  \nomit p and digit at the end\n```\nDEVICE=${DEVICE:-/dev/mmcblk1}\n```\n\nyour username is filled in automatically, to override edit USER\n```\nUSER=${USER:-`whoami`}\n```\n\n**changing default values by using environment variables**  \ndefault values can be overridden by passing them as env vars\n\nfor example to set DEVICE and READ enter at the command line  \n`$ sudo DEVICE=/dev/sdb READ=false ./shrink.sh`\n\nexplore the top of the script to configure some more things\n\n---\n\n### **remarks**\n\\- use this script completely at your own risk  \nbe sure to have backups of your data\n\n\\- new versions not widely tested yet  \nlook for previous versions in directory 'deprecated'\n\n\\- runs on physical or virtual Linux desktop systems\n\n\\- cannot handle Raspberry NOOBS images\n\n\\- do not shrink images to minimum  \notherwise they won't start on your Raspberry  \nespecially Raspbian Full *Desktop* images need some extra space, about >= 250 MB are advised  \nRaspbian *Lite* images might be more moderate\n\n\\- when starting from a shrinked SD card for the first time  \nexpand the filesystem to fill its space\n\nby raspi-config  \n`sudo raspi-config` -> *Expand Filesystem*  \n`sudo reboot`  \n**or**  \nfrom command line  \n`sudo raspi-config --expand-rootfs`  \n`sudo reboot`  \n\n\\- the script is 'half automatic'  \nmeaning at one point it will start GParted on desktop and guide you what to do\n\n\\- progress display of 'fill empty space' may not end at 100 % exactly  \nbecause of difficult file system overhead calculation  \nnevertheless space will be filled correctly  \n\n\\- the script was developed and tested on a VirtualBox Windows host with Linux Mint guest\n\n\\- inspired by  \n[http://www.aoakley.com/articles/2015-10-09-resizing-sd-images.php](http://www.aoakley.com/articles/2015-10-09-resizing-sd-images.php)\n\nDonations are welcome!\n\n[![https://www.paypal.com](https://www.paypalobjects.com/webstatic/en_US/btn/btn_donate_pp_142x27.png)](https://www.paypal.com/donate?business=qrt@qland.de&currency_code=USD&amount=5.00)\n\n\n---\n\n### history  \nV0.5  \ninitial version, script keel fix by Barleyman  \n\nV0.6  \nmmcblk naming support\n\nV0.7  \nsimplifications\n\nV0.71  \nadaption for parted 3.2, p -> print\n\nV0.8  \nautomated size retrieving from GParted  \nprogress bars with ETA for all time consuming actions\n\nV0.81  \ndefault value override by environment variables  \nthanks to Leon Miller-Out\n\nV0.9  \nargument handling and help screen  \nthanks to Pedro Figueiredo e Silva\n\nV0.91  \nlow memory warning  \ngparted details path hint\n\nV0.92  \ndependency tests  \nthanks to Tom Troyer\n\nV0.93  \ncorrection for chown warning\n\n- - -\n\n### copyright  \nshrink is published under the terms of ISC license\n\nCopyright (c) 2025 [qrt@qland.de](mailto:qrt@qland.de)\n\nPermission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n"
  },
  {
    "path": "deprecated/readme_071.md",
    "content": "# shrink V0.71\nthere is also a [newer version](README.md)\n\n#### Linux bash script to resize Raspberry SD card images  \nconsider further [remarks](#remarks)\n\n\n#### download  \ndownload repository from GitHub,  \nunzip and copy for example to: ~/shrink\n\n**or**\n\ncopy script to current directory  \n`wget https://raw.github.com/qrti/shrink/master/script/shrink_071.sh`\n\n**or**\n\ncheck if git is installed  \n`$ git --version`\n\nif git is not installed  \n`$ sudo apt-get install git-all`\n\nclone shrink repository to current directory  \n`$ git clone https://github.com/qrti/shrink.git`\n\n- - -\n\n#### necessary installs  \n`$ sudo apt-get install gparted`  \n`$ sudo apt-get install dcfldd`\n\n- - -\n\n#### configure  \nbefore executing the script the first time, insert your SD card\n\nenter the following at the command line and find the name of your SD device and partitions  \n`$ df -h`\n\nedit the script and enter your data between the quotation marks  \n`$ nano shrink_071.sh`\n\nexample for /dev/sdd1 + 2 (omit digit)\n```\nDEVICE=\"/dev/sdd\"\n```\n\nexample for /dev/mmcblk0p1 + 2 (omit px)\n```\nDEVICE=\"/dev/mmcblk0\"\n```\n\nfill in your Linux user name at USER\n```\nUSER=\"your user name\"\n```\n\nexplore the top of the script to configure some more things\n\n- - -\n\n#### execute  \nchange directory  \n`$ cd ~/shrink`\n\nmake script executable once  \n`$ chmod 755 shrink_071.sh`  \n**or**  \n`$ chmod a+x shrink_071.sh`\n\nexecute script  \n`$ sudo ./shrink_071.sh`\n\n- - -\n\n#### remarks  \n\\- use this script completely at your own risk  \n\n\\- runs on physical or virtual Linux desktop systems\n\n\\- cannot handle NOOBS images  \n\n\\- do not shrink images to minimum, otherwise they won't start on your Raspberry, especially Raspbian Full *Desktop* images need some extra space, about >= 250 MB are advised, Raspbian *Lite* images might be more moderate  \n\n\\- when starting from a shrinked SD card for the first time, expand the filesystem to fill its space  \n\nby raspi-config  \n`sudo raspi-config` -> *Expand Filesystem*  \n`sudo reboot`  \n  \n**or** from command line  \n`sudo raspi-config --expand-rootfs`  \n`sudo reboot`  \n\n\\- the script is 'half automatic', meaning at one point it will start GParted on desktop and guide you what to do  \n\n\\- the script was developed and tested on a VirtualBox Windows host with Linux Mint guest  \n\n\\- inspired by  \n[http://www.aoakley.com/articles/2015-10-09-resizing-sd-images.php](http://www.aoakley.com/articles/2015-10-09-resizing-sd-images.php)\n\nDonations are welcome!\n\n[![https://www.paypal.com](https://www.paypalobjects.com/webstatic/en_US/btn/btn_donate_pp_142x27.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E7JNEDMHAJ3TJ)\n\n- - -\n\n#### history  \nV0.5  \ninitial version, script keel fix by Barleyman  \n\nV0.6  \nmmcblk naming support\n\nV0.7  \nsimplifications\n\nV0.71  \nadaption for parted 3.2, p -> print\n\n- - -\n\n#### copyright  \nshrink is published under the terms of ISC license\n\nCopyright (c) 2018 [qrt@qland.de](mailto:qrt@qland.de)\n\nPermission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n"
  },
  {
    "path": "deprecated/readme_081.md",
    "content": "# shrink\n\n**Linux bash script to resize Raspberry SD card images**  \nconsider further [remarks](#remarks)\n\n### new version\n\\- automated size retrieving from GParted  \n\\- progress bars with ETA for all time consuming actions  \n\\- environment variable support\n\n**not widely tested yet, be sure to have backups of your data**  \nor use [previous version](readme_071.md)\n\n### download  \ndownload repository from GitHub,  \nunzip and copy for example to: ~/shrink\n\n**or**\n\ncopy script to current directory  \n`wget https://raw.github.com/qrti/shrink/master/script/shrink.sh`\n\n**or**\n\ncheck if git is installed  \n`$ git --version`\n\nif git is not installed  \n`$ sudo apt-get install git-all`\n\nclone shrink repository to current directory  \n`$ git clone https://github.com/qrti/shrink.git`\n\n- - -\n\n### necessary installs  \n`$ sudo apt-get install gparted`  \n`$ sudo apt-get install pv`\n\n- - -\n\n### configure  \nbefore executing the script the first time, insert your SD card\n\nenter the following at the command line and find the name of your SD device and partitions  \n`$ df -h`\n\nedit the script and enter your data between the quotation marks  \n`$ nano shrink.sh`\n\nexample for /dev/sdb1 + 2 (omit digit)\n```\nDEVICE=${DEVICE:-/dev/sdb}\n```\n\nexample for /dev/mmcblk0p1 + 2 (omit p and digit)\n```\nDEVICE=${DEVICE:-/dev/mmcblk0}\n```\n\nyour username is filled in automatically, to override edit USER\n```\nUSER=${USER:-`whoami`}\n```\n\n**using environment  variables**  \ndefault values can be overridden by passing them as env vars\n\nfor example to set DEVICE and READ enter at the command line  \n`$ sudo DEVICE=/dev/sdb READ=false ./shrink.sh`\n\nexplore the top of the script to configure some more things\n\n- - -\n\n### execute  \nchange directory  \n`$ cd ~/shrink`\n\nmake script executable once  \n`$ chmod 755 shrink.sh`  \n**or**  \n`$ chmod a+x shrink.sh`\n\nexecute script  \n`$ sudo ./shrink.sh`\n\n- - -\n\n### remarks  \n\\- use this script completely at your own risk\n\n\\- runs on physical or virtual Linux desktop systems\n\n\\- cannot handle NOOBS images\n\n\\- do not shrink images to minimum, otherwise they won't start on your Raspberry, especially Raspbian Full *Desktop* images need some extra space, about >= 250 MB are advised, Raspbian *Lite* images might be more moderate\n\n\\- when starting from a shrinked SD card for the first time, expand the filesystem to fill its space\n\nby raspi-config  \n`sudo raspi-config` -> *Expand Filesystem*  \n`sudo reboot`  \n**or**  \nfrom command line  \n`sudo raspi-config --expand-rootfs`  \n`sudo reboot`  \n\n\\- the script is 'half automatic', meaning at one point it will start GParted on desktop and guide you what to do\n\n\\- progress display of 'fill empty space' may not end at 100 % exactly because of difficult file system overhead calculation, nevertheless space will be filled correctly\n\n\\- the script was developed and tested on a VirtualBox Windows host with Linux Mint guest\n\n\\- inspired by  \n[http://www.aoakley.com/articles/2015-10-09-resizing-sd-images.php](http://www.aoakley.com/articles/2015-10-09-resizing-sd-images.php)\n\nDonations are welcome!\n\n[![https://www.paypal.com](https://www.paypalobjects.com/webstatic/en_US/btn/btn_donate_pp_142x27.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E7JNEDMHAJ3TJ)\n\n- - -\n\n### history  \nV0.5  \ninitial version, script keel fix by Barleyman  \n\nV0.6  \nmmcblk naming support\n\nV0.7  \nsimplifications\n\nV0.71  \nadaption for parted 3.2, p -> print\n\nV0.8  \nautomated size retrieving from GParted  \nprogress bars with ETA for all time consuming actions\n\nV0.81  \ndefault value override by environment variables  \nthanks to Leon Miller-Out\n\n- - -\n\n### copyright  \nshrink is published under the terms of ISC license\n\nCopyright (c) 2018 [qrt@qland.de](mailto:qrt@qland.de)\n\nPermission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n"
  },
  {
    "path": "deprecated/shrink_071.sh",
    "content": "#!/bin/bash\n\n# shrink V0.71 180527 qrt@qland.de\n# linux bash script to resize Raspberry SD card images \n#\n# inspired by\n# http://www.aoakley.com/articles/2015-10-09-resizing-sd-images.php\n#\n# necessary installs\n# sudo apt-get update && sudo apt-get install dcfldd\n# sudo apt-get update && sudo apt-get install gparted\n\nDEVICE=\"/dev/sdd\"           # source and target SD card device, examples: /dev/sdd, /dev/mmcblk0 ...\nUSER=\"your user name\"       # linux user name\nIMAGE_NAME=\"image\"          # image name, alternative with date and time: \"image_$(date +\"%y%m%d%H%M%S\")\"\nIMAGE=\"${IMAGE_NAME}.img\"   # image name with extension\nLOOP=$(losetup -f)\n\nREAD=true                   # read image from SD card (false for an already existing image)\nRESIZE=true                 # resize image with GParted\nFILL=true                   # fill empty space of new image with zeroes, only possible if RESIZE=true\nCOMPRESS=false              # compress new image (an extra file is generated)\nWRITE=false                 # write new image to SD card\n\npause(){\n    printf \"\\n\"\n    printf \"$1\\n\"\n    read -p \"press [Enter] to continue, CTRL-C to abort\" key\n    printf \"\\n\"\n}\n\ncheckDevice(){\n    if [ \"$1\" == \"\" -o \"$(df -h --output=source | grep \"$DEVICE\")\" == \"\" ]; then\n        printf \"device '$1' does not exist\\n\"\n        printf \"> check SD card devices with 'df -h'\\n\"\n        printf \"> re-insert SD card if necessary\\n\"\n        printf \"> edit DEVICE= in script if necessary\\n\\n\"\n        exit 1\n    fi\n}\n\necho \"shrink V0.71 180527 qrt@qland.de\"\n\nif [ $(id -u) -ne 0 ]; then\n    printf \"\\n\"\n    printf \"script must be run as root\\n\"\n    printf \"> try 'sudo ./shrink'\\n\\n\"\n    exit 1\nfi\n\nif [ \"$USER\" == \"\" ]; then\n    printf \"\\n\"\n    printf \"user not set\\n\"\n    printf \"> edit USER= in script\\n\\n\"\n    exit 1\nfi\n\nif [ $READ == true ]; then\n    if [ -f $IMAGE ]; then\n        pause \"file '$IMAGE' already exists and will be overwritten\"\n        echo -ne '\\033[1A'              # one line up\n    fi\n\n    pause \"insert source SD card and >>> close all popup file manager windows <<<\"\n    checkDevice $DEVICE\n\n    sudo umount $DEVICE?*               && echo unmount    ok || exit 1\n    sudo dcfldd if=$DEVICE of=$IMAGE    && echo image read ok || exit 1\n    sudo sync\n\n    pause \"remove SD card\"\n    echo -ne '\\033[1A'                  # one line up\nfi\n\necho\nsudo chown $USER.$USER $IMAGE           && echo owner and group ok || exit 1\n\nif [ $RESIZE == true ]; then\n    #sudo fdisk -l $IMAGE\n    #read -p \"enter Start of part 2: \" start\n    start=\"$(sudo parted $IMAGE -ms unit s print | grep \"^2\" | cut -f2 -d: | sed 's/[^0-9]*//g')\"\n\n    sudo losetup -d $LOOP >/dev/null 2>&1  # remove possible open loop\n    sudo losetup $LOOP $IMAGE -o $((start*512)) && echo loop setup ok || exit 1\n\n    echo\n    echo \"GParted desktop is started now\"\n    echo \"- go to GParted desktop window\"\n    echo \"- select '$LOOP'\"\n    echo \"- menu 'Partition / Resize/Move'\"\n    echo \"- change value of 'New Size' about >= 250 MB above 'Minimum Size'\"\n    echo \"- press button 'Resize/Move'\"\n    echo \"- menu 'Edit / Apply All Operations' and press Apply\"\n    echo \"- wait until GParted is ready - do not close dialog yet\"\n    echo \"- expand 'Details / Shrink.. / shrink.. / resize2fs -p $LOOP xxxxxxxK'\"\n    echo \"- note down size xxxxxxx\"\n    echo \"- close dialog and exit GParted\"\n\n    sudo gparted $LOOP >/dev/null 2>&1     # supresses GLib messages\n\n    echo\n    read -p \"enter noted size xxxxxxxx: \" size\n    echo\n\n    sudo losetup -d $LOOP          && echo loop remove ok || exit 1\n    sudo losetup $LOOP $IMAGE      && echo loop setup  ok || exit 1\n\n    newsize=\"+${size}K\"\n    printf \"d\\n2\\nn\\np\\n2\\n$start\\n$newsize\\np\\nw\\n\" | sudo fdisk $LOOP >/dev/null 2>&1\n    echo resize ok\n\n    #sudo fdisk -l $LOOP\n    #read -p \"enter End of part 2: \" end\n    end=\"$(sudo parted $LOOP -ms unit s print | grep \"^2\" | cut -f3 -d: | sed 's/[^0-9]*//g')\"\n\n    sudo losetup -d $LOOP          && echo loop remove ok || exit 1\n    truncate -s $(((end+1)*512)) $IMAGE && echo truncate    ok || exit 1\n\n    if [ $FILL == true ]; then\n        echo\n        echo fill empty space\n        sudo losetup $LOOP $IMAGE -o $((start*512))\n        sudo mkdir -p /mnt/imageroot\n        sudo mount $LOOP /mnt/imageroot\n        sudo dcfldd if=/dev/zero of=/mnt/imageroot/zero.txt\n        sudo rm /mnt/imageroot/zero.txt\n        sudo umount /mnt/imageroot\n        sudo rmdir /mnt/imageroot\n        sudo losetup -d $LOOP\n        echo fill empty space ok\n    fi\nfi\n\nif [ $COMPRESS == true ]; then\n    echo\n    echo compress image\n    zip $IMAGE_NAME.zip $IMAGE          && echo compress    ok || echo compress    failed\nfi\n\nif [ $WRITE == true ]; then\n    pause \"insert target SD card and >>> close all popup file manager windows <<<\"\n    checkDevice $DEVICE\n\n    sudo umount $DEVICE?*               && echo unmount     ok || exit 1\n    sudo dcfldd if=$IMAGE of=$DEVICE    && echo image write ok || exit 1\n    sudo sync\n\n    echo\n    echo remove SD card\nfi\n\necho\necho ready\necho\n"
  },
  {
    "path": "deprecated/shrink_081.sh",
    "content": "#!/bin/bash\n\n# shrink V0.81 180707 qrt@qland.de\n# linux bash script to resize Raspberry SD card images, progress version\n#\n# inspired by\n# http://www.aoakley.com/articles/2015-10-09-resizing-sd-images.php\n\n# make script executable once\n# chmod a+x shrink.sh\n\n# necessary installs\n# sudo apt-get install gparted\n# sudo apt-get install pv\n\n###\n# configuration\n# default values can be overridden by passing them as env vars\n# e.g. sudo DEVICE=/dev/sda READ=false ./shrink.sh\n###\nUSER=${USER:-`whoami`}                    # specify user who should own output files\nDEVICE=${DEVICE:-/dev/sdb}                # source and target SD card device, examples: /dev/sdd, /dev/mmcblk0 ...\nIMAGE_NAME=${IMAGE_NAME:-image}           # image name, alternative with date and time: \"image_$(date +\"%y%m%d%H%M%S\")\"\nIMAGE=${IMAGE:-${IMAGE_NAME}.img}         # image name with extension\nDETAILS=${DETAILS:-~/gparted_details.htm} # gparted details file path and name\n\nREAD=${READ:-true}              # read image from SD card (false for an already existing image)\nRESIZE=${RESIZE:-true}          # resize image with GParted\nFILL=${FILL:-true}              # fill empty space of new image with zeroes, only possible if RESIZE=true\nCOMPRESS=${COMPRESS:-false}     # compress new image (an extra file is generated)\nWRITE=${WRITE:-false}           # write new image to SD card\n\n\nLOOP=$(losetup -f)\n\npause(){\n    printf \"\\n\"\n    printf \"$1\\n\"\n    read -p \"press [Enter] to continue, CTRL-C to abort\" key\n    printf \"\\n\"\n}\n\ncheckDevice(){\n    if [ \"$1\" == \"\" -o \"$(df -h --output=source | grep \"$DEVICE\")\" == \"\" ]; then\n        printf \"device '$1' does not exist\\n\"\n        printf \"> check SD card devices with 'df -h'\\n\"\n        printf \"> re-insert SD card if necessary\\n\"\n        printf \"> edit DEVICE= in script if necessary\\n\\n\"\n        exit 1\n    fi\n}\n\necho \"shrink V0.81 180707 qrt@qland.de\"\n\nif [ $(id -u) -ne 0 ]; then\n    printf \"\\n\"\n    printf \"script must be run as root\\n\"\n    printf \"> try 'sudo ./shrink'\\n\\n\"\n    exit 1\nfi\n\nif [ \"$USER\" == \"\" ]; then\n    printf \"\\n\"\n    printf \"user not set\\n\"\n    printf \"> edit USER= in script\\n\\n\"\n    exit 1\nfi\n\nif [ $READ == true ]; then\n    if [ -f $IMAGE ]; then\n        pause \"file '$IMAGE' already exists and will be overwritten\"\n        echo -ne '\\033[1A'              # one line up\n    fi\n\n    pause \"insert source SD card and >>> close all popup file manager windows <<<\"\n    checkDevice $DEVICE\n    bsize=\"$(($(blockdev --getsize64 $DEVICE)/1024))K\"\n    sudo umount $DEVICE?*               && echo unmount    ok || exit 1\n    echo\n    echo \"generate image from SD card\"\n    sudo dd if=$DEVICE status=none | pv -s $bsize | dd of=$IMAGE bs=4096 status=none \\\n                                        && echo image read ok || exit 1\n    sudo sync\n\n    pause \"remove SD card\"\n    echo -ne '\\033[1A'                  # one line up\nfi\n\necho\nsudo chown $USER.$USER $IMAGE           && echo owner and group ok || exit 1\n\nif [ $RESIZE == true ]; then\n    #sudo fdisk -l $IMAGE\n    #read -p \"enter Start of part 2: \" start\n    start=\"$(sudo parted $IMAGE -ms unit s print | grep \"^2\" | cut -f2 -d: | sed 's/[^0-9]*//g')\"\n\n    sudo losetup -d $LOOP >/dev/null 2>&1  # remove possible open loop\n    sudo losetup $LOOP $IMAGE -o $((start*512)) && echo loop setup ok || exit 1\n\n    echo\n    echo \"GParted desktop is started now\"\n    echo \"- go to GParted desktop window\"\n    echo \"- select '$LOOP'\"\n    echo \"- menu 'Partition / Resize/Move'\"\n    echo \"- change value of 'New Size' about >= 250 MB above 'Minimum Size'\"\n    echo \"- press button 'Resize/Move'\"\n    echo \"- menu 'Edit / Apply All Operations' and press Apply\"\n    echo \"- wait until GParted is ready - do not close dialog yet\"\n    echo \"- press button 'Save Details' and 'Save' in file requester\"\n    echo \"- close dialog and exit GParted\"\n    echo\n\n    rm -f ~/gparted_details.htm         # remove old details\n\n    sudo gparted $LOOP >/dev/null 2>&1  # supresses GLib messages\n\n    if [ ! -f $DETAILS ]; then          # check details exist\n        echo \"gparted details file not found\"\n        exit 1\n    fi\n\n    size=$(awk '/resize2fs -p / {print $4;}' $DETAILS | awk 'BEGIN { FS=\"K\"; } { print $1; }')\n\n    rm -f ~/gparted_details.htm         # remove details\n\n    if [ -z $size ]; then               # check size\n        echo \"size not found in details\"\n        exit 1\n    elif [ $size -lt 512000 ]; then\n        echo \"suspicious small filesize\"\n        exit 1\n    fi\n\n    sudo losetup -d $LOOP               && echo loop remove ok || exit 1\n    sudo losetup $LOOP $IMAGE           && echo loop setup  ok || exit 1\n\n    newsize=\"+${size}K\"\n    printf \"d\\n2\\nn\\np\\n2\\n$start\\n$newsize\\np\\nw\\n\" | sudo fdisk $LOOP >/dev/null 2>&1\n    echo resize ok\n\n    #sudo fdisk -l $LOOP\n    #read -p \"enter End of part 2: \" end\n    end=\"$(sudo parted $LOOP -ms unit s print | grep \"^2\" | cut -f3 -d: | sed 's/[^0-9]*//g')\"\n\n    sudo losetup -d $LOOP               && echo loop remove ok || exit 1\n    truncate -s $(((end+1)*512)) $IMAGE && echo truncate    ok || exit 1\n\n    if [ $FILL == true ]; then\n        echo\n        echo fill empty space\n        sudo losetup $LOOP $IMAGE -o $((start*512))\n        sudo mkdir -p /mnt/imageroot\n        sudo mount $LOOP /mnt/imageroot\n        bsize=\"$(($(df -h -B1K | grep ^$LOOP | awk '{print $4}')*11/10))K\"      # +10% progress bar fs overhead correction\n        sudo dd if=/dev/zero | pv -s $bsize | dd of=/mnt/imageroot/zero.txt >/dev/null 2>&1\n        sudo rm /mnt/imageroot/zero.txt\n        sudo umount /mnt/imageroot\n        sudo rmdir /mnt/imageroot\n        sudo losetup -d $LOOP\n        echo fill empty space ok\n    fi\nfi\n\nif [ $COMPRESS == true ]; then\n    echo\n    echo compress image\n    tar pcf - $IMAGE | pv -s $(du -sb $IMAGE | awk '{print $1}') | gzip > $IMAGE_NAME.tar.gz \\\n                                        && echo compress    ok || echo compress    failed\nfi\n\nif [ $WRITE == true ]; then\n    pause \"insert target SD card and >>> close all popup file manager windows <<<\"\n    checkDevice $DEVICE\n    bsize=\"$(($(blockdev --getsize64 $DEVICE)/1024))K\"\n    sudo umount $DEVICE?*               && echo unmount     ok || exit 1\n    echo\n    echo \"write image to SD card\"\n    sudo dd if=$IMAGE status=none | pv -s $bsize | dd of=$DEVICE bs=4096 status=none \\\n                                        && echo image write ok || exit 1\n    sudo sync\n\n    echo\n    echo remove SD card\nfi\n\necho\necho ready\necho\n"
  },
  {
    "path": "deprecated/shrink_092.sh",
    "content": "#!/bin/bash\n\n# shrink V0.92 191008 qrt@qland.de\n# linux bash script to resize Raspberry SD card images, progress version\n#\n# inspired by\n# http://www.aoakley.com/articles/2015-10-09-resizing-sd-images.php\n\n# make script executable once\n# chmod a+x shrink.sh\n\n# necessary installs\n# sudo apt-get install gparted\n# sudo apt-get install pv\n\n###\n# configuration\n# default values can be overridden by passing them as env vars\n# e.g. sudo DEVICE=/dev/sda READ=false ./shrink.sh\n###\n\nSHRINK_VERSION=\"V0.92 191008\"\n\ntrap 'echo \"Aborting due to errexit on line $LINENO. Exit code: $?\" >&2' ERR\n\n\nUSER=${USER:-`whoami`}                    # specify user who should own output files\nDEVICE=${DEVICE:-/dev/sdb}                # source and target SD card device, examples: /dev/sdd, /dev/mmcblk0 ...\nIMAGE_NAME=${IMAGE_NAME:-image}           # image name, alternative with date and time: \"image_$(date +\"%y%m%d%H%M%S\")\"\nIMAGE=${IMAGE:-${IMAGE_NAME}.img}         # image name with extension\nDETAILS=${DETAILS:-~/gparted_details.htm} # gparted details file path and name\n\nREAD=${READ:-true}              # read image from SD card (false for an already existing image)\nRESIZE=${RESIZE:-true}          # resize image with GParted\nFILL=${FILL:-true}              # fill empty space of new image with zeroes, only possible if RESIZE=true\nCOMPRESS=${COMPRESS:-false}     # compress new image (an extra file is generated)\nWRITE=${WRITE:-false}           # write new image to SD card\n\n\nLOOP=$(losetup -f)\n\n\n_ME=$(basename \"${0}\")\n\n_print_help() {\n  cat <<HEREDOC\nShrink ${SHRINK_VERSION} qrt@qland.de\n\nLinux bash script to resize Raspberry SD card images, progress version.\n\nInspired by:\n   http://www.aoakley.com/articles/2015-10-09-resizing-sd-images.php\n\nNecessary steps:\n  make script executable once\n  chmod a+x shrink.sh\n\nNecessary installs:\n  sudo apt-get install gparted\n  sudo apt-get install pv\n\nUsage:\n  (sudo) ${_ME} [<arguments>]\n  (sudo) ${_ME} -h | --help\n  (sudo) ${_ME}\n\nOptions:\n  -h --help             show this screen\n  --user                specify user who should own output files (default: ${USER})\n  --device              source and target SD card device (default: ${DEVICE})\n  --date_name           image name, alternative with date and time: \"image_$(date +\"%y%m%d%H%M%S\") (default: ${IMAGE_NAME})\"\n  --image               image name with extension (default: ${IMAGE})\n  --details             gparted details file path and name (default: ${DETAILS})\n  --compress            compress new image (an extra file is generated) (default: ${COMPRESS})\n  --write               write new image to SD card (default: ${WRITE})\n  --skip-read           read image from SD card (false for an already existing image) (default: ${READ})\n  --skip-resize         resize image with GParted (default: ${RESIZE})\n  --skip-fill           fill empty space of new image with zeroes, only possible if RESIZE=true (default: ${FILL})\n\nHEREDOC\n}\n\nfunction _parse\n{\n    # Gather commands\n    while (( \"${#}\" ))\n    do\n        case \"${1}\" in\n            --user)\n            USER=\"${2}\"\n            shift\n            shift\n            ;;\n            --device)\n            DEVICE=\"${2}\"\n            shift\n            shift\n            ;;\n            --date_name)\n            IMAGE_NAME=\"image_$(date +\"%y%m%d%H%M%S\")\"\n            shift\n            ;;\n            --image)\n            IMAGE=\"${2}\"\n            shift\n            shift\n            ;;\n            --details)\n            DETAILS=\"${2}\"\n            shift\n            shift\n            ;;\n            --skip-read)\n            READ=false\n            shift\n            ;;\n            --skip-resize)\n            RESIZE=false\n            shift\n            ;;\n            --skip-fill)\n            FILL=false\n            shift\n            ;;\n            --compress)\n            COMPRESS=true\n            shift\n            ;;\n            --write)\n            WRITE=true\n            shift\n            ;;\n            *|-*|--*=) # unsupported flags\n            echo \"Unknown ${1}\"\n            exit 1\n            ;;\n        esac\n    done\n}\n\n\npause(){\n    printf \"\\n\"\n    printf \"$1\\n\"\n    read -p \"press [Enter] to continue, CTRL-C to abort\" key\n    printf \"\\n\"\n}\n\ncheckDevice(){\n    if [ \"$1\" == \"\" -o \"$(df -h --output=source | grep \"$DEVICE\")\" == \"\" ]; then\n        printf \"device '$1' does not exist\\n\"\n        printf \"> check SD card devices with 'df -h'\\n\"\n        printf \"> re-insert SD card if necessary\\n\"\n        printf \"> edit DEVICE= in script if necessary\\n\\n\"\n        exit 1\n    fi\n}\n\nfunction _main\n{\n    echo \"shrink ${SHRINK_VERSION} qrt@qland.de\"\n\n    if [ $(id -u) -ne 0 ]; then\n        printf \"\\n\"\n        printf \"script must be run as root\\n\"\n        printf \"> try 'sudo ./shrink'\\n\\n\"\n        exit 1\n    fi\n\n    if [ \"$USER\" == \"\" ]; then\n        printf \"\\n\"\n        printf \"user not set\\n\"\n        printf \"> edit USER= in script\\n\\n\"\n        exit 1\n    fi\n\n    if [ $READ == true ]; then\n        if [ -f $IMAGE ]; then\n            pause \"file '$IMAGE' already exists and will be overwritten\"\n            echo -ne '\\033[1A'              # one line up\n        fi\n\n        pause \"insert source SD card and >>> close all popup file manager windows <<<\"\n        checkDevice $DEVICE\n        \n        bsizek=$(($(blockdev --getsize64 $DEVICE)/1024))\n        bsizem=$(($bsizek/1024))\n        freem=$((`df -k --output=avail \"$PWD\" | tail -n1`/1024))\n\n        if [ $freem -lt $(($bsizem*3)) ]; then\n            pause \"warning: free memory \"$freem\"M is possibly too low for image (+ zip)\"\n            echo -ne '\\033[1A'              # one line up\n        fi\n\n        sudo umount $DEVICE?*               && echo unmount    ok || exit 1\n        echo\n        echo \"generate image from SD card\"\n        bsize=$bsizek\"K\"\n        sudo dd if=$DEVICE status=none | pv -s $bsize | dd of=$IMAGE bs=4096 status=none \\\n                                            && echo image read ok || exit 1\n        sudo sync\n\n        pause \"remove SD card\"\n        echo -ne '\\033[1A'                  # one line up\n    fi\n\n    echo\n    sudo chown $USER.$USER $IMAGE           && echo owner and group ok || exit 1\n\n    if [ $RESIZE == true ]; then\n        #sudo fdisk -l $IMAGE\n        #read -p \"enter Start of part 2: \" start\n        start=\"$(sudo parted $IMAGE -ms unit s print | grep \"^2\" | cut -f2 -d: | sed 's/[^0-9]*//g')\"\n\n        sudo losetup -d ${LOOP} >/dev/null 2>&1  # remove possible open loop\n        sudo losetup ${LOOP} ${IMAGE} -o $((start*512)) && echo loop setup ok || exit 1\n\n        echo\n        echo \"GParted desktop is started now\"\n        echo \"- go to GParted desktop window\"\n        echo \"- select '$LOOP'\"\n        echo \"- menu 'Partition / Resize/Move'\"\n        echo \"- change value of 'New Size' about >= 250 MB above 'Minimum Size'\"\n        echo \"- press button 'Resize/Move'\"\n        echo \"- menu 'Edit / Apply All Operations' and press Apply\"\n        echo \"- wait until GParted is ready - do not close dialog yet\"\n        echo \"- press button 'Save Details' and 'Save' in file requester\"\n        echo \"  details are saved to $DETAILS\"\n        echo \"- close dialog and exit GParted\"\n        echo\n\n        rm -f ~/gparted_details.htm         # remove old details\n\n        sudo gparted $LOOP >/dev/null 2>&1  # supresses GLib messages\n\n        if [ ! -f $DETAILS ]; then          # check details exist\n            echo \"gparted details file not found\"\n            exit 1\n        fi\n\n        size=$(awk '/resize2fs -p / {print $4;}' $DETAILS | awk 'BEGIN { FS=\"K\"; } { print $1; }')\n\n        rm -f ~/gparted_details.htm         # remove details\n\n        if [ -z $size ]; then               # check size\n            echo \"size not found in details\"\n            exit 1\n        elif [ $size -lt 512000 ]; then\n            echo \"suspicious small filesize\"\n            exit 1\n        fi\n\n        sudo losetup -d $LOOP               && echo loop remove ok || exit 1\n        sudo losetup $LOOP $IMAGE           && echo loop setup  ok || exit 1\n\n        newsize=\"+${size}K\"\n        printf \"d\\n2\\nn\\np\\n2\\n$start\\n$newsize\\np\\nw\\n\" | sudo fdisk $LOOP >/dev/null 2>&1\n        echo resize ok\n\n        #sudo fdisk -l $LOOP\n        #read -p \"enter End of part 2: \" end\n        end=\"$(sudo parted $LOOP -ms unit s print | grep \"^2\" | cut -f3 -d: | sed 's/[^0-9]*//g')\"\n\n        sudo losetup -d $LOOP               && echo loop remove ok || exit 1\n        truncate -s $(((end+1)*512)) $IMAGE && echo truncate    ok || exit 1\n\n        if [ $FILL == true ]; then\n            echo\n            echo fill empty space\n            sudo losetup $LOOP $IMAGE -o $((start*512))\n            sudo mkdir -p /mnt/imageroot\n            sudo mount $LOOP /mnt/imageroot\n            bsize=\"$(($(df -h -B1K | grep ^$LOOP | awk '{print $4}')*11/10))K\"      # +10% progress bar fs overhead correction\n            sudo dd if=/dev/zero | pv -s $bsize | dd of=/mnt/imageroot/zero.txt >/dev/null 2>&1\n            sudo rm /mnt/imageroot/zero.txt\n            sudo umount /mnt/imageroot\n            sudo rmdir /mnt/imageroot\n            sudo losetup -d $LOOP\n            echo fill empty space ok\n        fi\n    fi\n\n    if [ $COMPRESS == true ]; then\n        echo\n        echo compress image\n        tar pcf - $IMAGE | pv -s $(du -sb $IMAGE | awk '{print $1}') | gzip > $IMAGE_NAME.tar.gz \\\n                                            && echo compress    ok || echo compress    failed\n    fi\n\n    if [ $WRITE == true ]; then\n        pause \"insert target SD card and >>> close all popup file manager windows <<<\"\n        checkDevice $DEVICE\n        bsize=\"$(($(blockdev --getsize64 $DEVICE)/1024))K\"\n        sudo umount $DEVICE?*               && echo unmount     ok || exit 1\n        echo\n        echo \"write image to SD card\"\n        sudo dd if=$IMAGE status=none | pv -s $bsize | dd of=$DEVICE bs=4096 status=none \\\n                                            && echo image write ok || exit 1\n        sudo sync\n\n        echo\n        echo remove SD card\n    fi\n\n    echo\n    echo ready\n    echo\n}\n\n\nif [ \"${1:-}\" == -h ] || [ \"${1:-}\" == --help ]; then\n    _print_help\nelse\n    # check script dependencies\n    command -v gparted >/dev/null 2>&1 || { echo >&2 \"Cannot locate gparted. Is it installed? Aborting.\"; exit 1; }\n    command -v pv      >/dev/null 2>&1 || { echo >&2 \"Cannot locate pv. Is it installed? Aborting.\";      exit 1; }\n\n    echo \"calling parser\"\n    _parse \"$@\"\n    _main \"$@\"\nfi\n"
  },
  {
    "path": "script/shrink.sh",
    "content": "#!/bin/bash\n\n# shrink V0.93 241231 qrt@qland.de\n# linux bash script to resize Raspberry SD card images, progress version\n#\n# inspired by\n# http://www.aoakley.com/articles/2015-10-09-resizing-sd-images.php\n\n# make script executable once\n# chmod a+x shrink.sh\n\n# necessary installs\n# sudo apt-get install gparted\n# sudo apt-get install pv\n\n###\n# configuration\n# default values can be overridden by passing them as env vars\n# e.g. sudo DEVICE=/dev/sda READ=false ./shrink.sh\n###\n\nSHRINK_VERSION=\"V0.93 241231\"\n\ntrap 'echo \"Aborting due to errexit on line $LINENO. Exit code: $?\" >&2' ERR\n\n\nUSER=${USER:-`whoami`}                    # specify user who should own output files\nDEVICE=${DEVICE:-/dev/sdb}                # source and target SD card device, examples: /dev/sdd, /dev/mmcblk0 ...\nIMAGE_NAME=${IMAGE_NAME:-image}           # image name, alternative with date and time: \"image_$(date +\"%y%m%d%H%M%S\")\"\nIMAGE=${IMAGE:-${IMAGE_NAME}.img}         # image name with extension\nDETAILS=${DETAILS:-~/gparted_details.htm} # gparted details file path and name\n\nREAD=${READ:-true}              # read image from SD card (false for an already existing image)\nRESIZE=${RESIZE:-true}          # resize image with GParted\nFILL=${FILL:-true}              # fill empty space of new image with zeroes, only possible if RESIZE=true\nCOMPRESS=${COMPRESS:-false}     # compress new image (an extra file is generated)\nWRITE=${WRITE:-false}           # write new image to SD card\n\n\nLOOP=$(losetup -f)\n\n\n_ME=$(basename \"${0}\")\n\n_print_help() {\n  cat <<HEREDOC\nShrink ${SHRINK_VERSION} qrt@qland.de\n\nLinux bash script to resize Raspberry SD card images, progress version.\n\nInspired by:\n   http://www.aoakley.com/articles/2015-10-09-resizing-sd-images.php\n\nNecessary steps:\n  make script executable once\n  chmod a+x shrink.sh\n\nNecessary installs:\n  sudo apt-get install gparted\n  sudo apt-get install pv\n\nUsage:\n  (sudo) ${_ME} [<arguments>]\n  (sudo) ${_ME} -h | --help\n  (sudo) ${_ME}\n\nOptions:\n  -h --help             show this screen\n  --user                specify user who should own output files (default: ${USER})\n  --device              source and target SD card device (default: ${DEVICE})\n  --date_name           image name, alternative with date and time: \"image_$(date +\"%y%m%d%H%M%S\") (default: ${IMAGE_NAME})\"\n  --image               image name with extension (default: ${IMAGE})\n  --details             gparted details file path and name (default: ${DETAILS})\n  --compress            compress new image (an extra file is generated) (default: ${COMPRESS})\n  --write               write new image to SD card (default: ${WRITE})\n  --skip-read           read image from SD card (false for an already existing image) (default: ${READ})\n  --skip-resize         resize image with GParted (default: ${RESIZE})\n  --skip-fill           fill empty space of new image with zeroes, only possible if RESIZE=true (default: ${FILL})\n\nHEREDOC\n}\n\nfunction _parse\n{\n    # Gather commands\n    while (( \"${#}\" ))\n    do\n        case \"${1}\" in\n            --user)\n            USER=\"${2}\"\n            shift\n            shift\n            ;;\n            --device)\n            DEVICE=\"${2}\"\n            shift\n            shift\n            ;;\n            --date_name)\n            IMAGE_NAME=\"image_$(date +\"%y%m%d%H%M%S\")\"\n            shift\n            ;;\n            --image)\n            IMAGE=\"${2}\"\n            shift\n            shift\n            ;;\n            --details)\n            DETAILS=\"${2}\"\n            shift\n            shift\n            ;;\n            --skip-read)\n            READ=false\n            shift\n            ;;\n            --skip-resize)\n            RESIZE=false\n            shift\n            ;;\n            --skip-fill)\n            FILL=false\n            shift\n            ;;\n            --compress)\n            COMPRESS=true\n            shift\n            ;;\n            --write)\n            WRITE=true\n            shift\n            ;;\n            *|-*|--*=) # unsupported flags\n            echo \"Unknown ${1}\"\n            exit 1\n            ;;\n        esac\n    done\n}\n\n\npause(){\n    printf \"\\n\"\n    printf \"$1\\n\"\n    read -p \"press [Enter] to continue, CTRL-C to abort\" key\n    printf \"\\n\"\n}\n\ncheckDevice(){\n    if [ \"$1\" == \"\" -o \"$(df -h --output=source | grep \"$DEVICE\")\" == \"\" ]; then\n        printf \"device '$1' does not exist\\n\"\n        printf \"> check SD card devices with 'df -h'\\n\"\n        printf \"> re-insert SD card if necessary\\n\"\n        printf \"> edit DEVICE= in script if necessary\\n\\n\"\n        exit 1\n    fi\n}\n\nfunction _main\n{\n    echo \"shrink ${SHRINK_VERSION} qrt@qland.de\"\n\n    if [ $(id -u) -ne 0 ]; then\n        printf \"\\n\"\n        printf \"script must be run as root\\n\"\n        printf \"> try 'sudo ./shrink'\\n\\n\"\n        exit 1\n    fi\n\n    if [ \"$USER\" == \"\" ]; then\n        printf \"\\n\"\n        printf \"user not set\\n\"\n        printf \"> edit USER= in script\\n\\n\"\n        exit 1\n    fi\n\n    if [ $READ == true ]; then\n        if [ -f $IMAGE ]; then\n            pause \"file '$IMAGE' already exists and will be overwritten\"\n            echo -ne '\\033[1A'              # one line up\n        fi\n\n        pause \"insert source SD card and >>> close all popup file manager windows <<<\"\n        checkDevice $DEVICE\n        \n        bsizek=$(($(blockdev --getsize64 $DEVICE)/1024))\n        bsizem=$(($bsizek/1024))\n        freem=$((`df -k --output=avail \"$PWD\" | tail -n1`/1024))\n\n        if [ $freem -lt $(($bsizem*3)) ]; then\n            pause \"warning: free memory \"$freem\"M is possibly too low for image (+ zip)\"\n            echo -ne '\\033[1A'              # one line up\n        fi\n\n        sudo umount $DEVICE?*               && echo unmount    ok || exit 1\n        echo\n        echo \"generate image from SD card\"\n        bsize=$bsizek\"K\"\n        sudo dd if=$DEVICE status=none | pv -s $bsize | dd of=$IMAGE bs=4096 status=none \\\n                                            && echo image read ok || exit 1\n        sudo sync\n\n        pause \"remove SD card\"\n        echo -ne '\\033[1A'                  # one line up\n    fi\n\n    echo\n    sudo chown $USER:$USER $IMAGE           && echo owner and group ok || exit 1\n\n    if [ $RESIZE == true ]; then\n        #sudo fdisk -l $IMAGE\n        #read -p \"enter Start of part 2: \" start\n        start=\"$(sudo parted $IMAGE -ms unit s print | grep \"^2\" | cut -f2 -d: | sed 's/[^0-9]*//g')\"\n\n        sudo losetup -d ${LOOP} >/dev/null 2>&1  # remove possible open loop\n        sudo losetup ${LOOP} ${IMAGE} -o $((start*512)) && echo loop setup ok || exit 1\n\n        echo\n        echo \"GParted desktop is started now\"\n        echo \"- go to GParted desktop window\"\n        echo \"- select '$LOOP'\"\n        echo \"- menu 'Partition / Resize/Move'\"\n        echo \"- change value of 'New Size' about >= 250 MB above 'Minimum Size'\"\n        echo \"- press button 'Resize/Move'\"\n        echo \"- menu 'Edit / Apply All Operations' and press Apply\"\n        echo \"- wait until GParted is ready - do not close dialog yet\"\n        echo \"- press button 'Save Details' and 'Save' in file requester\"\n        echo \"  details are saved to $DETAILS\"\n        echo \"- close dialog and exit GParted\"\n        echo\n\n        rm -f ~/gparted_details.htm         # remove old details\n\n        sudo gparted $LOOP >/dev/null 2>&1  # supresses GLib messages\n\n        if [ ! -f $DETAILS ]; then          # check details exist\n            echo \"gparted details file not found\"\n            exit 1\n        fi\n\n        size=$(awk '/resize2fs -p / {print $4;}' $DETAILS | awk 'BEGIN { FS=\"K\"; } { print $1; }')\n\n        rm -f ~/gparted_details.htm         # remove details\n\n        if [ -z $size ]; then               # check size\n            echo \"size not found in details\"\n            exit 1\n        elif [ $size -lt 512000 ]; then\n            echo \"suspicious small filesize\"\n            exit 1\n        fi\n\n        sudo losetup -d $LOOP               && echo loop remove ok || exit 1\n        sudo losetup $LOOP $IMAGE           && echo loop setup  ok || exit 1\n\n        newsize=\"+${size}K\"\n        printf \"d\\n2\\nn\\np\\n2\\n$start\\n$newsize\\np\\nw\\n\" | sudo fdisk $LOOP >/dev/null 2>&1\n        echo resize ok\n\n        #sudo fdisk -l $LOOP\n        #read -p \"enter End of part 2: \" end\n        end=\"$(sudo parted $LOOP -ms unit s print | grep \"^2\" | cut -f3 -d: | sed 's/[^0-9]*//g')\"\n\n        sudo losetup -d $LOOP               && echo loop remove ok || exit 1\n        truncate -s $(((end+1)*512)) $IMAGE && echo truncate    ok || exit 1\n\n        if [ $FILL == true ]; then\n            echo\n            echo fill empty space\n            sudo losetup $LOOP $IMAGE -o $((start*512))\n            sudo mkdir -p /mnt/imageroot\n            sudo mount $LOOP /mnt/imageroot\n            bsize=\"$(($(df -h -B1K | grep ^$LOOP | awk '{print $4}')*11/10))K\"      # +10% progress bar fs overhead correction\n            sudo dd if=/dev/zero | pv -s $bsize | dd of=/mnt/imageroot/zero.txt >/dev/null 2>&1\n            sudo rm /mnt/imageroot/zero.txt\n            sudo umount /mnt/imageroot\n            sudo rmdir /mnt/imageroot\n            sudo losetup -d $LOOP\n            echo fill empty space ok\n        fi\n    fi\n\n    if [ $COMPRESS == true ]; then\n        echo\n        echo compress image\n        tar pcf - $IMAGE | pv -s $(du -sb $IMAGE | awk '{print $1}') | gzip > $IMAGE_NAME.tar.gz \\\n                                            && echo compress    ok || echo compress    failed\n    fi\n\n    if [ $WRITE == true ]; then\n        pause \"insert target SD card and >>> close all popup file manager windows <<<\"\n        checkDevice $DEVICE\n        bsize=\"$(($(blockdev --getsize64 $DEVICE)/1024))K\"\n        sudo umount $DEVICE?*               && echo unmount     ok || exit 1\n        echo\n        echo \"write image to SD card\"\n        sudo dd if=$IMAGE status=none | pv -s $bsize | dd of=$DEVICE bs=4096 status=none \\\n                                            && echo image write ok || exit 1\n        sudo sync\n\n        echo\n        echo remove SD card\n    fi\n\n    echo\n    echo ready\n    echo\n}\n\n\nif [ \"${1:-}\" == -h ] || [ \"${1:-}\" == --help ]; then\n    _print_help\nelse\n    # check script dependencies\n    command -v gparted >/dev/null 2>&1 || { echo >&2 \"Cannot locate gparted. Is it installed? Aborting.\"; exit 1; }\n    command -v pv      >/dev/null 2>&1 || { echo >&2 \"Cannot locate pv. Is it installed? Aborting.\";      exit 1; }\n\n    echo \"calling parser\"\n    _parse \"$@\"\n    _main \"$@\"\nfi\n"
  }
]