diff --git a/.gitarchiveinclude b/.gitarchiveinclude index 0a250d8..c3e3dfa 100644 --- a/.gitarchiveinclude +++ b/.gitarchiveinclude @@ -1,3 +1,4 @@ +ca-certificates.crt bin/h700/minui-list bin/h700/minui-presenter bin/m17/minui-list diff --git a/.gitignore b/.gitignore index c3e77dd..7e39d29 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ bin/* !bin/.gitkeep res/fonts/* !res/fonts/.gitkeep +ca-certificates.crt !bin/on-boot diff --git a/Makefile b/Makefile index f05755d..0da5e97 100644 --- a/Makefile +++ b/Makefile @@ -14,12 +14,13 @@ clean: rm -f bin/*/jq* || true rm -f bin/*/tailscale* || true rm -f bin/*/tailscaled* || true + rm -f ca-certificates.crt || true bump-version: jq '.version = "$(RELEASE_VERSION)"' pak.json > pak.json.tmp mv pak.json.tmp pak.json -build: $(foreach platform,$(PLATFORMS),bin/$(platform)/minui-list bin/$(platform)/minui-presenter) $(foreach arch,$(ARCHITECTURES),bin/$(arch)/jq bin/$(arch)/tailscale bin/$(arch)/tailscaled) +build: $(foreach platform,$(PLATFORMS),bin/$(platform)/minui-list bin/$(platform)/minui-presenter) $(foreach arch,$(ARCHITECTURES),bin/$(arch)/jq bin/$(arch)/tailscale bin/$(arch)/tailscaled) ca-certificates.crt @echo "Build complete" bin/%/minui-list: @@ -86,6 +87,9 @@ bin/%/tailscaled: chmod +x bin/$*/tailscaled curl -sSL -o bin/$*/tailscaled.LICENSE "https://github.com/tailscale/tailscale/raw/refs/heads/main/LICENSE" +ca-certificates.crt: + curl -f -o ca-certificates.crt -sSL https://curl.se/ca/cacert.pem + release: build mkdir -p dist git archive --format=zip --output "dist/$(PAK_NAME).pak.zip" HEAD diff --git a/README.md b/README.md index ed79c69..83e1983 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,10 @@ Debug logs are written to the `$SDCARD_PATH/.userdata/$PLATFORM/logs/` folder. - [NextUI](https://github.com/LoveRetro/NextUI) by [@ro8inmorgan](https://github.com/ro8inmorgan), [@frysee](https://github.com/frysee) and the rest of the NextUI contributors. - Also, thank you, [Jose Diaz-Gonzalez](https://github.com/josegonzalez), for your pak repositories, which this project is based on. +## Custom login server (Headscale) + +If you use a self-hosted Headscale or other custom login server, create a file named `loginserver` containing only the base URL of your login server (for example, `https://headscale.example.com`). Drop the file on the root of your SD card or directly into `$USERDATA_PATH/$PAK_NAME`. On launch, the pak cleans the value, moves it into `$USERDATA_PATH/$PAK_NAME/loginserver`, and automatically passes it to `tailscale up` using `--login-server`. + ## License -This project is released under the MIT License. For more information, see the [LICENSE](LICENSE) file. \ No newline at end of file +This project is released under the MIT License. For more information, see the [LICENSE](LICENSE) file. diff --git a/bin/on-boot b/bin/on-boot index 4266239..a020824 100755 --- a/bin/on-boot +++ b/bin/on-boot @@ -18,6 +18,7 @@ if uname -m | grep -q '64'; then fi export PATH="$PAK_DIR/bin/$architecture:$PAK_DIR/bin/$PLATFORM:$PAK_DIR/bin:$PATH" +export SSL_CERT_FILE="$PAK_DIR/ca-certificates.crt" main() { "$PAK_DIR/bin/$architecture/tailscaled" --statedir="$USERDATA_PATH/$PAK_NAME/" --no-logs-no-support & diff --git a/launch.sh b/launch.sh index 498c056..ccd8022 100644 --- a/launch.sh +++ b/launch.sh @@ -19,11 +19,15 @@ fi export PATH="$PAK_DIR/bin/$architecture:$PAK_DIR/bin/$PLATFORM:$PAK_DIR/bin:$PATH" +export SSL_CERT_FILE="$PAK_DIR/ca-certificates.crt" + SERVICE_NAME="tailscaled" HUMAN_READABLE_NAME="Tailscale VPN" LAUNCHES_SCRIPT="false" TAILSCALE_AUTHKEY_FILE="$SDCARD_PATH/authkey" +TAILSCALE_LOGIN_SERVER_FILE="$SDCARD_PATH/loginserver" +TAILSCALE_LOGIN_SERVER_STORAGE_FILE="$USERDATA_PATH/$PAK_NAME/loginserver" service_off() { killall "$SERVICE_NAME" @@ -140,9 +144,50 @@ current_settings() { tailscale_login() { authkey="$1" - if ! tailscale up --authkey="$authkey" --hostname="minui" --accept-routes --accept-dns; then + tailscale_args="--authkey=$authkey --hostname=minui --accept-routes --accept-dns" + + if login_server="$(tailscale_get_login_server)"; then + tailscale_args="$tailscale_args --login-server=$login_server" + fi + + # shellcheck disable=SC2086 + if ! tailscale up $tailscale_args; then + return 1 + fi +} + +tailscale_get_login_server() { + loginserver_file="$TAILSCALE_LOGIN_SERVER_STORAGE_FILE" + + tailscale_sync_login_server + + if [ ! -f "$loginserver_file" ] || [ ! -s "$loginserver_file" ]; then return 1 fi + + tr -d '\r' <"$loginserver_file" | tr -d '\n' +} + +tailscale_sync_login_server() { + source_file="$TAILSCALE_LOGIN_SERVER_FILE" + target_file="$TAILSCALE_LOGIN_SERVER_STORAGE_FILE" + + if [ ! -f "$source_file" ] || [ ! -s "$source_file" ]; then + return 1 + fi + + mkdir -p "$(dirname "$target_file")" + tr -d '\r' <"$source_file" | tr -d '\n' >"$target_file.tmp" + + if ! cmp -s "$target_file.tmp" "$target_file"; then + mv "$target_file.tmp" "$target_file" + else + rm -f "$target_file.tmp" + fi + + rm -f "$source_file" + sync + return 0 } tailscale_start() {