54 lines
2.2 KiB
Bash
Executable File
54 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
||
# Установка esim-tools на OpenWrt, по ssh на роутере:
|
||
# wget -qO- https://git.sam-hub.net/sam/esim-tools/raw/branch/main/install.sh | sh
|
||
# или после tools/push.sh с компьютера:
|
||
# sh /etc/esim-tools/install.sh
|
||
# Ставит недостающие пакеты (lpac, uqmi, sms-tool, jsonfilter, curl), скрипт
|
||
# /usr/bin/esim и страницу LuCI: Модем -> esim-tools.
|
||
set -eu
|
||
KIT_URL=${KIT_URL:-https://git.sam-hub.net/sam/esim-tools/archive/main.tar.gz}
|
||
KIT_DIR=/etc/esim-tools
|
||
|
||
# пакеты: opkg (до 24.10) или apk (25.x)
|
||
missing=
|
||
for p in lpac:lpac uqmi:uqmi sms_tool:sms-tool jsonfilter:jsonfilter curl:curl; do
|
||
command -v "${p%%:*}" >/dev/null 2>&1 || missing="$missing ${p#*:}"
|
||
done
|
||
if [ -n "$missing" ]; then
|
||
echo "ставлю:$missing"
|
||
if command -v apk >/dev/null 2>&1; then
|
||
apk update && apk add $missing
|
||
else
|
||
opkg update && opkg install $missing
|
||
fi
|
||
fi
|
||
|
||
here=$(cd "$(dirname "$0")" 2>/dev/null && pwd || echo /nonexistent)
|
||
mkdir -p "$KIT_DIR"
|
||
if [ -f "$here/router/esim.sh" ]; then
|
||
[ "$here" = "$KIT_DIR" ] || cp -r "$here/router" "$here/luci" "$here/install.sh" "$KIT_DIR/"
|
||
else
|
||
tmp=/tmp/esim-tools.$$
|
||
mkdir -p "$tmp"
|
||
echo "скачиваю $KIT_URL"
|
||
wget -qO "$tmp/kit.tgz" "$KIT_URL"
|
||
tar xzf "$tmp/kit.tgz" -C "$tmp"
|
||
src=$(find "$tmp" -path '*/router/esim.sh' | head -n 1)
|
||
[ -n "$src" ] || { echo "ошибка: в $KIT_URL нет router/esim.sh" >&2; exit 1; }
|
||
src=${src%/router/esim.sh}
|
||
for d in router luci; do
|
||
rm -rf "${KIT_DIR:?}/$d"
|
||
cp -r "$src/$d" "$KIT_DIR/"
|
||
done
|
||
cp "$src/install.sh" "$KIT_DIR/"
|
||
# id коммита из заголовка git archive (как kit_version в esim.sh)
|
||
sha=$(gunzip -c "$tmp/kit.tgz" | head -c 1536 | tr -c 'a-z0-9=\n' '\n' |
|
||
grep '^comment=[0-9a-f]\{40\}$' | head -n 1 | cut -c9-15) || true
|
||
echo "${sha:-?} $(date '+%Y-%m-%d %H:%M')" > "$KIT_DIR/VERSION"
|
||
rm -rf "$tmp"
|
||
fi
|
||
sh "$KIT_DIR/router/esim.sh" install
|
||
ip=$(uci -q get network.lan.ipaddr | cut -d/ -f1)
|
||
echo "Готово: http://${ip:-<роутер>}/cgi-bin/luci/admin/modem/esim-tools"
|
||
echo "(LuCI -> Modem -> esim-tools; если пункта нет - выйди из LuCI и войди снова)"
|