Skip to content

Commit

Permalink
autodetect mountpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
wertarbyte committed May 19, 2010
1 parent be6aed1 commit 1aa4104
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions adfree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@ fi

HOSTFILE=${1:-/etc/hosts}

# detect mountpoint of the host file
ETC_MOUNT="$(df -P "$HOSTFILE" | awk 'NR==2 { print $6 }')"

#################################################
set -e

echo "starting adfree v${VERSION}..."

is_rw() {
awk '$2 == "/system" && $4 ~/(^|,)rw(,|$)/ {RW=1} END{exit ! RW}' /proc/mounts
awk -vD="$ETC_MOUNT" '$2 == D && $4 ~/(^|,)rw(,|$)/ {RW=1} END{exit ! RW}' /proc/mounts
}

REMOUNTED=0
is_rw || { mount /system -o remount,rw; REMOUNTED=1; }
is_rw || { mount "$ETC_MOUNT" -o remount,rw; REMOUNTED=1; }

# better be safe than sorry...
is_rw || { echo "Unable to gain write access to /system, aborting" >&2; exit 1; }
is_rw || { echo "Unable to gain write access to $ETC_MOUNT, aborting" >&2; exit 1; }

# remove old adfree entries
echo "Removing ADFREE entries from $HOSTFILE"
Expand All @@ -66,7 +69,7 @@ if [ "$REMOVE_ONLY" -ne 1 ]; then
} 3>&1 >> "$HOSTFILE"
fi

# mount /system read-only if it was at the beginning
[ "$REMOUNTED" -eq 1 ] && mount /system -o remount,ro
# mount directory read-only if it was at the beginning
[ "$REMOUNTED" -eq 1 ] && mount "$ETC_MOUNT" -o remount,ro

echo "done."

0 comments on commit 1aa4104

Please sign in to comment.