Skip to content

Commit

Permalink
Add update checking!
Browse files Browse the repository at this point in the history
  • Loading branch information
Drewsif committed Oct 23, 2024
1 parent 6b73041 commit f3f2ece
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ using multiple cores is supported.
## Usage ##

```text
Usage: $0 [-adhrsvzZ] imagefile.img [newimagefile.img]
Usage: pishrink.sh [-adhnrsvzZ] imagefile.img [newimagefile.img]
-s Don't expand filesystem when image is booted the first time
-v Be verbose
-n Disable automatic update checking
-r Use advanced filesystem repair option if the normal one fails
-z Compress image after shrinking with gzip
-Z Compress image after shrinking with xz
Expand All @@ -23,6 +24,7 @@ If you specify the `newimagefile.img` parameter, the script will make a copy of

* `-s` prevents automatic filesystem expansion on the images next boot
* `-v` enables more verbose output
* `-n` disables the script from checking Github for a new PiShrink release
* `-r` will attempt to repair the filesystem using additional options if the normal repair fails
* `-z` will compress the image after shrinking using gzip. `.gz` extension will be added to the filename.
* `-Z` will compress the image after shrinking using xz. `.xz` extension will be added to the filename.
Expand Down
17 changes: 14 additions & 3 deletions pishrink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ EOFRC
help() {
local help
read -r -d '' help << EOM
Usage: $0 [-adhrsvzZ] imagefile.img [newimagefile.img]
Usage: $0 [-adhnrsvzZ] imagefile.img [newimagefile.img]
-s Don't expand filesystem when image is booted the first time
-v Be verbose
-n Disable automatic update checking
-r Use advanced filesystem repair option if the normal one fails
-z Compress image after shrinking with gzip
-Z Compress image after shrinking with xz
Expand All @@ -185,15 +186,17 @@ EOM

should_skip_autoexpand=false
debug=false
update_check=true
repair=false
parallel=false
verbose=false
ziptool=""

while getopts ":adhrsvzZ" opt; do
while getopts ":adnhrsvzZ" opt; do
case "${opt}" in
a) parallel=true;;
d) debug=true;;
n) update_check=false;;
h) help;;
r) repair=true;;
s) should_skip_autoexpand=true ;;
Expand All @@ -214,6 +217,15 @@ fi

echo -e "PiShrink $version - https://github.com/Drewsif/PiShrink\n"

# Try and check for updates
if $update_check; then
latest_release=$(curl -m 5 https://api.github.com/repos/Drewsif/PiShrink/releases/latest 2>/dev/null | grep -i "tag_name" 2>/dev/null | awk -F '"' '{print $4}' 2>/dev/null)
if [[ $? ]] && [ "$latest_release" \> "$version" ]; then
echo "WARNING: You do not appear to be running the latest version of PiShrink. Head on over to https://github.com/Drewsif/PiShrink to grab $latest_release"
echo ""
fi
fi

#Args
src="$1"
img="$1"
Expand All @@ -239,7 +251,6 @@ export LANGUAGE=POSIX
export LC_ALL=POSIX
export LANG=POSIX


# check selected compression tool is supported and installed
if [[ -n $ziptool ]]; then
if [[ ! " ${ZIPTOOLS[@]} " =~ $ziptool ]]; then
Expand Down

0 comments on commit f3f2ece

Please sign in to comment.