|
@@ -4,6 +4,7 @@ set -eu
|
|
|
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
|
APP_DIR=$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)
|
|
APP_DIR=$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)
|
|
|
CONFIG_PATH=${1:-"$APP_DIR/router_local.conf"}
|
|
CONFIG_PATH=${1:-"$APP_DIR/router_local.conf"}
|
|
|
|
|
+CONFIG_DIR=$(CDPATH= cd -- "$(dirname -- "$CONFIG_PATH")" && pwd)
|
|
|
|
|
|
|
|
if [ ! -r "$CONFIG_PATH" ]; then
|
|
if [ ! -r "$CONFIG_PATH" ]; then
|
|
|
echo "[router-http] config not found: $CONFIG_PATH" >&2
|
|
echo "[router-http] config not found: $CONFIG_PATH" >&2
|
|
@@ -18,10 +19,33 @@ RUNTIME_DIR=${RUNTIME_DIR:-"$APP_DIR/cfip_runtime"}
|
|
|
VALUE_TEXT_FILE=${VALUE_TEXT_FILE:-"current_ip.txt"}
|
|
VALUE_TEXT_FILE=${VALUE_TEXT_FILE:-"current_ip.txt"}
|
|
|
HTTP_PORT=${HTTP_PORT:-8080}
|
|
HTTP_PORT=${HTTP_PORT:-8080}
|
|
|
|
|
|
|
|
|
|
+# Trim possible CRLF endings from config values edited on Windows/Web UI.
|
|
|
|
|
+CR=$(printf '\r')
|
|
|
|
|
+BUSYBOX_BIN=${BUSYBOX_BIN%"$CR"}
|
|
|
|
|
+RUNTIME_DIR=${RUNTIME_DIR%"$CR"}
|
|
|
|
|
+VALUE_TEXT_FILE=${VALUE_TEXT_FILE%"$CR"}
|
|
|
|
|
+HTTP_PORT=${HTTP_PORT%"$CR"}
|
|
|
|
|
+
|
|
|
TEXT_PATH="$RUNTIME_DIR/$VALUE_TEXT_FILE"
|
|
TEXT_PATH="$RUNTIME_DIR/$VALUE_TEXT_FILE"
|
|
|
INDEX_PATH="$RUNTIME_DIR/index.html"
|
|
INDEX_PATH="$RUNTIME_DIR/index.html"
|
|
|
|
|
|
|
|
|
|
+resolve_path_from_config() {
|
|
|
|
|
+ p="$1"
|
|
|
|
|
+ case "$p" in
|
|
|
|
|
+ /*) printf '%s\n' "$p" ;;
|
|
|
|
|
+ *) printf '%s/%s\n' "$CONFIG_DIR" "$p" ;;
|
|
|
|
|
+ esac
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
resolve_busybox() {
|
|
resolve_busybox() {
|
|
|
|
|
+ if [ -n "$BUSYBOX_BIN" ]; then
|
|
|
|
|
+ busybox_from_cfg=$(resolve_path_from_config "$BUSYBOX_BIN")
|
|
|
|
|
+ if [ -x "$busybox_from_cfg" ]; then
|
|
|
|
|
+ printf '%s\n' "$busybox_from_cfg"
|
|
|
|
|
+ return 0
|
|
|
|
|
+ fi
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
if [ -n "$BUSYBOX_BIN" ] && [ -x "$BUSYBOX_BIN" ]; then
|
|
if [ -n "$BUSYBOX_BIN" ] && [ -x "$BUSYBOX_BIN" ]; then
|
|
|
printf '%s\n' "$BUSYBOX_BIN"
|
|
printf '%s\n' "$BUSYBOX_BIN"
|
|
|
return 0
|
|
return 0
|
|
@@ -40,10 +64,43 @@ resolve_busybox() {
|
|
|
return 1
|
|
return 1
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+print_busybox_debug() {
|
|
|
|
|
+ echo "[router-http] debug CONFIG_PATH=$CONFIG_PATH" >&2
|
|
|
|
|
+ echo "[router-http] debug CONFIG_DIR=$CONFIG_DIR" >&2
|
|
|
|
|
+ echo "[router-http] debug APP_DIR=$APP_DIR" >&2
|
|
|
|
|
+ echo "[router-http] debug BUSYBOX_BIN(raw)=$BUSYBOX_BIN" >&2
|
|
|
|
|
+
|
|
|
|
|
+ resolved_from_cfg=$(resolve_path_from_config "$BUSYBOX_BIN")
|
|
|
|
|
+ echo "[router-http] debug BUSYBOX_BIN(resolved)=$resolved_from_cfg" >&2
|
|
|
|
|
+
|
|
|
|
|
+ if [ -e "$resolved_from_cfg" ]; then
|
|
|
|
|
+ if [ -x "$resolved_from_cfg" ]; then
|
|
|
|
|
+ echo "[router-http] debug resolved BusyBox exists and is executable" >&2
|
|
|
|
|
+ else
|
|
|
|
|
+ echo "[router-http] debug resolved BusyBox exists but is NOT executable; run: chmod +x $resolved_from_cfg" >&2
|
|
|
|
|
+ fi
|
|
|
|
|
+ else
|
|
|
|
|
+ echo "[router-http] debug resolved BusyBox does not exist" >&2
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ if [ -e "$APP_DIR/busybox_armv7l" ]; then
|
|
|
|
|
+ if [ -x "$APP_DIR/busybox_armv7l" ]; then
|
|
|
|
|
+ echo "[router-http] debug fallback $APP_DIR/busybox_armv7l exists and is executable" >&2
|
|
|
|
|
+ else
|
|
|
|
|
+ echo "[router-http] debug fallback $APP_DIR/busybox_armv7l exists but is NOT executable; run: chmod +x $APP_DIR/busybox_armv7l" >&2
|
|
|
|
|
+ fi
|
|
|
|
|
+ else
|
|
|
|
|
+ echo "[router-http] debug fallback $APP_DIR/busybox_armv7l does not exist" >&2
|
|
|
|
|
+ fi
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
busybox_has_applet() {
|
|
busybox_has_applet() {
|
|
|
busybox_bin="$1"
|
|
busybox_bin="$1"
|
|
|
applet="$2"
|
|
applet="$2"
|
|
|
- "$busybox_bin" --list 2>/dev/null | grep "^$applet$" >/dev/null
|
|
|
|
|
|
|
+ if "$busybox_bin" --list 2>/dev/null | grep "^$applet$" >/dev/null; then
|
|
|
|
|
+ return 0
|
|
|
|
|
+ fi
|
|
|
|
|
+ "$busybox_bin" 2>/dev/null | grep "[[:space:]]$applet[,[:space:]]" >/dev/null
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ensure_index() {
|
|
ensure_index() {
|
|
@@ -74,6 +131,7 @@ start_httpd() {
|
|
|
echo "[router-http] ASUS firmware httpd is usually the router admin web server and does not support serving an arbitrary -h directory" >&2
|
|
echo "[router-http] ASUS firmware httpd is usually the router admin web server and does not support serving an arbitrary -h directory" >&2
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
|
|
+ print_busybox_debug
|
|
|
echo "[router-http] usable BusyBox httpd applet not found" >&2
|
|
echo "[router-http] usable BusyBox httpd applet not found" >&2
|
|
|
echo "[router-http] set BUSYBOX_BIN in router_local.conf to your full BusyBox binary, for example: BUSYBOX_BIN=\"./busybox_armv7l\"" >&2
|
|
echo "[router-http] set BUSYBOX_BIN in router_local.conf to your full BusyBox binary, for example: BUSYBOX_BIN=\"./busybox_armv7l\"" >&2
|
|
|
exit 1
|
|
exit 1
|