Improved first install script
This commit is contained in:
parent
ef2c150c63
commit
e6b200b33a
20
README.md
20
README.md
@ -27,6 +27,18 @@ TOTP-секрет), Tailscale; «Сохранить и применить» со
|
||||
включает профиль и, если включён Tailscale, показывает ссылку для входа — открыть её,
|
||||
войти, в админке Tailscale **Disable key expiry** для ноды.
|
||||
|
||||
На новом роутере (ещё без настроек) установщик сразу настраивает nikki: перехват без TUN
|
||||
(TCP — redirect, UDP — tproxy, `tun_enabled=0`, как в облегчённом режиме) и IPv6 выключен
|
||||
везде (`mixin.ipv6`, `mixin.dns_ipv6`, `proxy.ipv6_dns_hijack`, `proxy.ipv6_proxy`). В форме
|
||||
торренты и обход для пушей по умолчанию выключены, а конфиг для телефона включён. Включение
|
||||
профиля (`use`, «Сохранить и применить») включает и nikki, в том числе автозапуск.
|
||||
|
||||
Маленькая флешка: opkg сравнивает свободное место с распакованным размером пакетов (у mihomo
|
||||
около 55 МБ), а сжимающий overlay (ubifs, jffs2) хранит их примерно в размере .ipk (около 20 МБ).
|
||||
Поэтому установщик сам считает место по .ipk и ставит с `--force-space`, а если места правда нет,
|
||||
останавливается до установки. Пакеты качаются в `/tmp`, весь вывод установки сохраняется в
|
||||
`/tmp/mihomo-kit-install.log`.
|
||||
|
||||
Позже настройки меняются там же — «Изменить настройки»; ключи, добавленные в
|
||||
`common.env` / `bmstu.env` руками, сохраняются.
|
||||
|
||||
@ -461,9 +473,11 @@ tproxy). Включить обратно — `uci set nikki.proxy.ipv6_proxy=1`,
|
||||
|
||||
## Телефон (FlClash)
|
||||
|
||||
С роутера: LuCI → Настройка → галка «Конфиг для телефона» → «Сохранить и применить». На
|
||||
странице появится блок «Телефон (FlClash)» с QR-кодом и ссылкой
|
||||
`http://<роутер>/mihomo-kit/<токен>.yaml`: FlClash → Профили → + → по ссылке (или QR).
|
||||
С роутера: LuCI → Настройка → галка «Конфиг для телефона» (на новом роутере уже стоит) →
|
||||
«Сохранить и применить». На странице появится блок «Телефон (FlClash)» с QR-кодом и ссылкой
|
||||
`http://<роутер>/mihomo-kit/<токен>.yaml`. В QR — ссылка импорта
|
||||
`clash://install-config?url=<ссылка>`: камера телефона откроет FlClash, и он добавит профиль.
|
||||
Вручную: «Скопировать ссылку» → FlClash → Профили → + → URL.
|
||||
Это `common.env`, собранный с `TARGET=mobile`: те же подписки, BOOT/`BOOT-AUTO`, HWID и
|
||||
RU-адреса, без OpenVPN, Tailscale, торрентов и `PUSH`; свои серверы — в `MY`, к ним всегда
|
||||
через `MY-EXIT` (телефон часто на белых списках). Пересобирается вместе с профилями.
|
||||
|
||||
15
install.sh
15
install.sh
@ -38,5 +38,16 @@ else
|
||||
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 "$@"
|
||||
# stdin may be the piped script: the wizard (setup --cli) reads answers from /dev/tty.
|
||||
# The output is also kept in RAM: the flash may be full by the time something fails.
|
||||
log=/tmp/mihomo-kit-install.log
|
||||
rc=/tmp/mihomo-kit-install.rc
|
||||
{
|
||||
code=0
|
||||
sh "$KIT_DIR/router/mihomo-kit.sh" setup "$@" 2>&1 || code=$?
|
||||
echo "$code" > "$rc"
|
||||
} | tee "$log"
|
||||
code=$(cat "$rc" 2>/dev/null || echo 1)
|
||||
rm -f "$rc"
|
||||
echo "install log: $log"
|
||||
exit "$code"
|
||||
|
||||
@ -422,10 +422,25 @@ return view.extend({
|
||||
|
||||
if (st.mobile_path) {
|
||||
var mobUrl = window.location.protocol + '//' + window.location.host + st.mobile_path;
|
||||
// the camera opens a plain link in the browser; the import link opens FlClash itself
|
||||
var importUrl = 'clash://install-config?url=' + encodeURIComponent(mobUrl) + '&name=mihomo-kit';
|
||||
var qrBox = E('div', { 'style': 'width:220px;max-width:100%;background:#fff;padding:8px;border-radius:4px' }, E('em', 'QR…'));
|
||||
var copied = E('span', { 'class': 'cbi-value-description' });
|
||||
var copy = function() {
|
||||
var done = function() { copied.textContent = ' скопировано'; };
|
||||
if (navigator.clipboard && window.isSecureContext)
|
||||
return navigator.clipboard.writeText(mobUrl).then(done);
|
||||
// http LuCI: no Clipboard API
|
||||
var t = E('textarea', { 'style': 'position:fixed;opacity:0' }, mobUrl);
|
||||
document.body.appendChild(t);
|
||||
t.select();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(t);
|
||||
done();
|
||||
};
|
||||
loadQr().then(function(qrcode) {
|
||||
var q = qrcode(0, 'M');
|
||||
q.addData(mobUrl);
|
||||
q.addData(importUrl);
|
||||
q.make();
|
||||
qrBox.innerHTML = q.createSvgTag({ cellSize: 4, margin: 2, scalable: true });
|
||||
}).catch(function(e) { dom.content(qrBox, String(e)); });
|
||||
@ -433,9 +448,15 @@ return view.extend({
|
||||
E('div', { 'style': 'display:flex;gap:1.5em;flex-wrap:wrap;align-items:flex-start' }, [
|
||||
qrBox,
|
||||
E('div', { 'style': 'flex:1;min-width:16em' }, [
|
||||
E('p', 'FlClash → Профили → + → по ссылке (или QR) — профиль из тех же подписок и BOOT, ' +
|
||||
'без OpenVPN, Tailscale и торрентов; свои серверы — через MY-EXIT.'),
|
||||
E('p', [ E('a', { 'href': mobUrl, 'target': '_blank', 'rel': 'noreferrer' }, mobUrl) ]),
|
||||
E('p', 'Профиль из тех же подписок и BOOT, без OpenVPN, Tailscale и торрентов; свои серверы — через MY-EXIT. ' +
|
||||
'QR — камерой телефона: откроется FlClash и добавит профиль. Или скопируй ссылку: ' +
|
||||
'FlClash → Профили → + → URL.'),
|
||||
E('p', [ E('code', { 'style': 'word-break:break-all' }, mobUrl) ]),
|
||||
E('p', [
|
||||
E('button', { 'class': 'btn cbi-button', 'click': copy }, 'Скопировать ссылку'), ' ',
|
||||
E('a', { 'class': 'btn cbi-button', 'href': importUrl }, 'Открыть в FlClash'),
|
||||
copied
|
||||
]),
|
||||
E('p', { 'class': 'cbi-value-description' }, 'Ссылка работает только в сети роутера: вне дома FlClash ' +
|
||||
'просто не обновит профиль. В ней ссылки подписок — не пересылай; «Новая ссылка» отзывает старую.'),
|
||||
this.button('Новая ссылка', 'negative', 'mobile-new', null,
|
||||
|
||||
10
luci/rpcd.sh
10
luci/rpcd.sh
@ -282,8 +282,9 @@ m_config_get() {
|
||||
json_add_string hwid_os_ver "${HWID_OS_VER:-${DISTRIB_RELEASE:-}}"
|
||||
json_add_string hwid_model "${HWID_MODEL:-$(cat /tmp/sysinfo/model 2>/dev/null)}"
|
||||
json_add_string hwid_id "${HWID_ID:-$(md5sum < /sys/class/net/br-lan/address 2>/dev/null | cut -c1-16)}"
|
||||
json_add_boolean torrent "${TORRENT:-1}"
|
||||
json_add_boolean push "${PUSH:-1}"
|
||||
# a new router: torrents and push off, the phone config on
|
||||
json_add_boolean torrent "${TORRENT:-0}"
|
||||
json_add_boolean push "${PUSH:-0}"
|
||||
json_add_string ru_ips "${RU_IPS:-}"
|
||||
json_add_string foreign_ips "${FOREIGN_IPS:-}"
|
||||
json_add_string my_ips "${MY_IPS:-}"
|
||||
@ -311,7 +312,12 @@ m_config_get() {
|
||||
json_add_string ts_domains "${TS_DOMAINS:-}"
|
||||
json_add_string ovpn_check_url "${OVPN_CHECK_URL:-https://eu.bmstu.ru}"
|
||||
json_add_string ts_check_url "${TS_CHECK_URL:-http://100.69.216.50:8080}"
|
||||
# common.env has MOBILE=1 only when on
|
||||
if [ -f "$PROFILES_D/common.env" ]; then
|
||||
json_add_boolean mobile "${MOBILE:-0}"
|
||||
else
|
||||
json_add_boolean mobile 1
|
||||
fi
|
||||
json_add_boolean lite "${LITE:-0}"
|
||||
json_add_string lite_gomemlimit "${LITE_GOMEMLIMIT:-}"
|
||||
json_add_array hy2
|
||||
|
||||
@ -1201,10 +1201,26 @@ lite_check() {
|
||||
return 0
|
||||
}
|
||||
|
||||
# A new router (no settings yet): interception without TUN, as LITE does (TCP
|
||||
# redirect, UDP tproxy), and no IPv6 anywhere in nikki. Once the settings are
|
||||
# saved, nikki's own settings are left to the user.
|
||||
nikki_defaults() {
|
||||
[ -f "$PROFILES_D/common.env" ] && return 0
|
||||
uci -q get nikki.proxy > /dev/null || return 0
|
||||
lite_intercept
|
||||
for _o in mixin.ipv6 mixin.dns_ipv6 proxy.ipv6_dns_hijack proxy.ipv6_proxy; do
|
||||
[ "$(uci -q get "nikki.$_o")" = 0 ] || { uci set "nikki.$_o=0" && log "nikki: $_o=0"; }
|
||||
done
|
||||
uci commit nikki
|
||||
}
|
||||
|
||||
cmd_use() {
|
||||
[ $# -eq 1 ] || die "usage: use <name>"
|
||||
[ -f "$PROFILES_OUT/$1.yaml" ] || die "no $PROFILES_OUT/$1.yaml, run build first"
|
||||
uci set nikki.config.profile="file:$1.yaml"
|
||||
# a profile to run: nikki on, also after a reboot
|
||||
[ "$(uci -q get nikki.config.enabled)" = 1 ] || { uci set nikki.config.enabled=1 && log "nikki: enabled"; }
|
||||
/etc/init.d/nikki enabled || /etc/init.d/nikki enable
|
||||
lite_uci "$1"
|
||||
csqtt_match_process "$1"
|
||||
ipv6_proxy_off
|
||||
@ -1706,17 +1722,47 @@ enable_otp_cron() {
|
||||
log "added bmstu-otp.sh check to cron"
|
||||
}
|
||||
|
||||
# opkg_fit <package>...: install from the feeds on a small flash. opkg checks every
|
||||
# package's Installed-Size (unpacked) against the free space, but a compressing
|
||||
# overlay (ubifs, jffs2) stores the files at about their .ipk size: mihomo is ~55 MB
|
||||
# unpacked and ~20 MB as .ipk, so opkg refuses what fits. Here the packages opkg
|
||||
# would install are counted by .ipk size there (Installed-Size on other file systems)
|
||||
# + PKG_RESERVE_KB, then --force-space. The .ipk files are downloaded to /tmp (RAM).
|
||||
opkg_fit() {
|
||||
_new=$(opkg --noaction --force-space install "$@" 2>/dev/null | sed -n 's/^Installing \([^ ]*\) (.*/\1/p')
|
||||
if [ -z "$_new" ]; then
|
||||
opkg install "$@"
|
||||
return
|
||||
fi
|
||||
_field=Installed-Size
|
||||
case "$(awk '$2 == "/overlay" {print $3; exit}' /proc/mounts)" in ubifs | jffs2) _field=Size ;; esac
|
||||
_need=0
|
||||
for _p in $_new; do
|
||||
_b=$(opkg info "$_p" | sed -n "s/^$_field: *//p" | head -n 1)
|
||||
case "$_b" in '' | *[!0-9]*) _b=0 ;; esac
|
||||
_need=$((_need + (_b + 1023) / 1024))
|
||||
done
|
||||
_free=$(df -k / 2>/dev/null | awk 'NR==2 {print $4}')
|
||||
_new=$(echo $_new)
|
||||
log "packages $_new: about $_need KB on flash ($_field), free ${_free:-?} KB"
|
||||
[ $((${_free:-0} - _need)) -ge "$PKG_RESERVE_KB" ] ||
|
||||
die "not enough flash for $_new: free $((PKG_RESERVE_KB + _need - ${_free:-0})) KB more"
|
||||
opkg install --force-space "$@"
|
||||
}
|
||||
|
||||
cmd_install() {
|
||||
opkg update
|
||||
if [ ! -x /etc/init.d/nikki ]; then
|
||||
wget -O - https://github.com/nikkinikki-org/OpenWrt-nikki/raw/refs/heads/main/feed.sh | ash
|
||||
opkg install nikki luci-app-nikki
|
||||
# feed.sh saves the feed key to the current directory
|
||||
(cd /tmp && wget -O - https://github.com/nikkinikki-org/OpenWrt-nikki/raw/refs/heads/main/feed.sh | ash)
|
||||
opkg_fit nikki luci-app-nikki
|
||||
fi
|
||||
for p in curl oath-toolkit; do
|
||||
opkg list-installed | grep -q "^$p " || opkg install "$p"
|
||||
opkg list-installed | grep -q "^$p " || opkg_fit "$p"
|
||||
done
|
||||
# curl newer than libcurl -> "Error relocating ... symbol not found"
|
||||
curl --version >/dev/null 2>&1 || opkg install --force-reinstall libcurl4 curl
|
||||
nikki_defaults
|
||||
install_files
|
||||
cmd_fix
|
||||
}
|
||||
@ -1884,8 +1930,8 @@ wizard() {
|
||||
"$(cat /sys/class/net/br-lan/address 2>/dev/null | md5sum | cut -c1-16)"
|
||||
fi
|
||||
|
||||
yesno TORRENT "Торренты через TORRENT-SEL (порты 20000-20199)" y
|
||||
yesno PUSH "Пуши (APNs, FCM) через группу PUSH" y
|
||||
yesno TORRENT "Торренты через TORRENT-SEL (порты 20000-20199)" n
|
||||
yesno PUSH "Пуши (APNs, FCM) через группу PUSH" n
|
||||
ask RU_IPS "Доп. IP через RU (CIDR через пробел)" ""
|
||||
ask FOREIGN_IPS "Доп. IP через FOREIGN (CIDR через пробел)" ""
|
||||
ask RU_DOMAINS "Доп. домены через RU (через пробел, с поддоменами)" ""
|
||||
@ -1982,7 +2028,7 @@ write_config() {
|
||||
echo "BOOT=$BOOT"
|
||||
[ "$BOOT" = 1 ] && echo "BOOT_LINKS=$(q "$BOOT_LINKS")"
|
||||
echo "TORRENT=$TORRENT"
|
||||
echo "PUSH=${PUSH:-1}"
|
||||
echo "PUSH=${PUSH:-0}"
|
||||
for v in RU_IPS FOREIGN_IPS RU_DOMAINS FOREIGN_DOMAINS; do
|
||||
eval "_v=\${$v:-}"
|
||||
[ -n "$_v" ] || [ "$v" = RU_IPS ] && echo "$v=$(q "$_v")"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user