2015-06-13 01:03:31 +02:00
|
|
|
#!/bin/sh
|
2016-09-14 23:57:33 +02:00
|
|
|
# clean.sh - clean everything.
|
|
|
|
set -e -u
|
2015-06-13 01:03:31 +02:00
|
|
|
|
2019-08-06 14:39:42 +02:00
|
|
|
# Checking if script is running on Android with 2 different methods.
|
|
|
|
# Needed for safety to prevent execution of potentially dangerous
|
|
|
|
# operations such as 'rm -rf /data/*' on Android device.
|
|
|
|
if [ "$(uname -o)" = "Android" ] || [ -e "/system/bin/app_process" ]; then
|
|
|
|
TERMUX_ON_DEVICE_BUILD=true
|
|
|
|
else
|
|
|
|
TERMUX_ON_DEVICE_BUILD=
|
|
|
|
fi
|
2016-06-04 00:41:30 +02:00
|
|
|
|
2019-08-06 14:39:42 +02:00
|
|
|
if [ "$(id -u)" = "0" ] && [ -n "$TERMUX_ON_DEVICE_BUILD" ]; then
|
|
|
|
echo "On-device execution of this script as root is disabled."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Read settings from .termuxrc if existing
|
|
|
|
test -f "$HOME/.termuxrc" && . "$HOME/.termuxrc"
|
|
|
|
: "${TERMUX_TOPDIR:="$HOME/.termux-build"}"
|
|
|
|
: "${TMPDIR:=/tmp}"
|
|
|
|
export TMPDIR
|
2019-07-08 16:51:38 +02:00
|
|
|
|
|
|
|
# Lock file. Same as used in build-package.sh.
|
2019-08-06 14:39:42 +02:00
|
|
|
TERMUX_BUILD_LOCK_FILE="${TMPDIR}/.termux-build.lck"
|
2019-07-08 16:51:38 +02:00
|
|
|
if [ ! -e "$TERMUX_BUILD_LOCK_FILE" ]; then
|
|
|
|
touch "$TERMUX_BUILD_LOCK_FILE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
{
|
|
|
|
if ! flock -n 5; then
|
|
|
|
echo "Not cleaning build directory since you have unfinished build running."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -d "$TERMUX_TOPDIR" ]; then
|
2019-08-06 14:39:42 +02:00
|
|
|
chmod +w -R "$TERMUX_TOPDIR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$TERMUX_ON_DEVICE_BUILD" ]; then
|
|
|
|
# For on-device build cleanup /data shouldn't be erased.
|
|
|
|
rm -Rf "$TERMUX_TOPDIR"
|
|
|
|
else
|
|
|
|
rm -Rf /data/* "$TERMUX_TOPDIR"
|
2019-07-08 16:51:38 +02:00
|
|
|
fi
|
|
|
|
} 5< "$TERMUX_BUILD_LOCK_FILE"
|