37 lines
1.6 KiB
Bash
Executable File
37 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# One-command setup of mihomo-kit on OpenWrt (nikki), over ssh on the router:
|
|
# wget -qO- https://git.sam-hub.net/sam/mihomo-kit/raw/branch/main/install.sh | sh
|
|
# or after tools/push.sh from a computer:
|
|
# sh /etc/nikki/kit/install.sh
|
|
# Installs nikki (if needed), the core, the fixes and the kit with its LuCI page;
|
|
# the settings are then made in LuCI -> Services -> mihomo-kit.
|
|
set -eu
|
|
KIT_URL=${KIT_URL:-https://git.sam-hub.net/sam/mihomo-kit/archive/main.tar.gz}
|
|
KIT_DIR=/etc/nikki/kit
|
|
|
|
here=$(cd "$(dirname "$0")" 2>/dev/null && pwd || echo /nonexistent)
|
|
mkdir -p "$KIT_DIR"
|
|
if [ -f "$here/router/mihomo-kit.sh" ]; then
|
|
[ "$here" = "$KIT_DIR" ] || cp -r "$here/templates" "$here/presets" "$here/router" "$here/luci" "$KIT_DIR/"
|
|
else
|
|
tmp=/tmp/mihomo-kit.$$
|
|
mkdir -p "$tmp"
|
|
echo "downloading $KIT_URL"
|
|
wget -qO "$tmp/kit.tgz" "$KIT_URL"
|
|
tar xzf "$tmp/kit.tgz" -C "$tmp"
|
|
src=$(find "$tmp" -path '*/router/mihomo-kit.sh' | head -n 1)
|
|
[ -n "$src" ] || { echo "error: no router/mihomo-kit.sh in $KIT_URL" >&2; exit 1; }
|
|
src=${src%/router/mihomo-kit.sh}
|
|
for d in templates presets router luci; do
|
|
rm -rf "${KIT_DIR:?}/$d"
|
|
cp -r "$src/$d" "$KIT_DIR/"
|
|
done
|
|
# commit id from the git archive header (same as kit_version in mihomo-kit.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
|
|
# stdin may be the piped script: the wizard (setup --cli) reads answers from /dev/tty
|
|
exec sh "$KIT_DIR/router/mihomo-kit.sh" setup "$@"
|