Skip to content

Commit

Permalink
Fixes for rc.local issues
Browse files Browse the repository at this point in the history
- Display warning when no existing /etc/rc.local is found
- Only try to run old /etc/rc.local if it actually exists

Closes #151
Closes #267
  • Loading branch information
Drewsif committed Dec 1, 2023
1 parent 48d1756 commit aa14313
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pishrink.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

version="v0.1.3"
version="v0.1.4"

CURRENT_DIR="$(pwd)"
SCRIPTNAME="${0##*/}"
Expand Down Expand Up @@ -84,7 +84,11 @@ function set_autoexpand() {
return
fi

if [[ -f "$mountdir/etc/rc.local" ]] && [[ "$(md5sum "$mountdir/etc/rc.local" | cut -d ' ' -f 1)" != "1c579c7d5b4292fd948399b6ece39009" ]]; then
if [[ ! -f "$mountdir/etc/rc.local" ]]; then
info "An existing /etc/rc.local was not found, autoexpand may fail..."
fi

if [[ -f "$mountdir/etc/rc.local" ]] && [[ "$(md5sum "$mountdir/etc/rc.local" | cut -d ' ' -f 1)" != "5c286b336c0606ed8e6f87708f7802eb" ]]; then
echo "Creating new /etc/rc.local"
if [ -f "$mountdir/etc/rc.local" ]; then
mv "$mountdir/etc/rc.local" "$mountdir/etc/rc.local.bak"
Expand Down Expand Up @@ -124,7 +128,7 @@ cat <<EOF > /etc/rc.local &&
#!/bin/sh
echo "Expanding /dev/$ROOT_PART"
resize2fs /dev/$ROOT_PART
rm -f /etc/rc.local; cp -f /etc/rc.local.bak /etc/rc.local; /etc/rc.local
rm -f /etc/rc.local; cp -fp /etc/rc.local.bak /etc/rc.local && /etc/rc.local
EOF
reboot
Expand All @@ -135,7 +139,7 @@ raspi_config_expand() {
if [[ $? != 0 ]]; then
return -1
else
rm -f /etc/rc.local; cp -f /etc/rc.local.bak /etc/rc.local; /etc/rc.local
rm -f /etc/rc.local; cp -fp /etc/rc.local.bak /etc/rc.local && /etc/rc.local
reboot
exit
fi
Expand All @@ -147,7 +151,7 @@ do_expand_rootfs
echo "ERROR: Expanding failed..."
sleep 5
if [[ -f /etc/rc.local.bak ]]; then
cp -f /etc/rc.local.bak /etc/rc.local
cp -fp /etc/rc.local.bak /etc/rc.local
/etc/rc.local
fi
exit 0
Expand Down

0 comments on commit aa14313

Please sign in to comment.