feat: 初始化跨平台远程编译服务与 Android Studio 插件
This commit is contained in:
commit
9eba4556db
44 files changed
+2802
No files matched your search
Executable
+78
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env bash
|
||||
# Usage: sudo bash install.sh /path/to/remotecompile-linux-amd64
|
||||
# Optional: JAVA_HOME, ANDROID_HOME, ANDROID_SDK_ROOT (existing readable toolchains).
|
||||
set -euo pipefail
|
||||
if [[ $(id -u) != 0 ]]; then echo 'Run as root or through sudo.' >&2; exit 1; fi
|
||||
if [[ $(uname -m) != x86_64 ]]; then echo 'This package requires x86_64 Linux.' >&2; exit 1; fi
|
||||
binary=${1:?Provide the uploaded Linux amd64 executable}
|
||||
[[ -f "$binary" ]] || { echo 'Binary does not exist' >&2; exit 1; }
|
||||
if ! id remotecompile >/dev/null 2>&1; then
|
||||
useradd --system --create-home --home-dir /var/lib/remotecompile --shell /usr/sbin/nologin remotecompile
|
||||
fi
|
||||
install -d -m 0755 /opt/remotecompile/bin
|
||||
install -d -m 0700 /etc/remotecompile
|
||||
install -d -o remotecompile -g remotecompile -m 0700 /var/lib/remotecompile /var/lib/remotecompile/data
|
||||
if [[ ! -f /etc/remotecompile/environment ]]; then
|
||||
umask 077
|
||||
token=$(od -An -N32 -tx1 /dev/urandom | tr -d ' \n')
|
||||
printf 'REMOTE_BUILD_TOKEN=%s\nHOME=/var/lib/remotecompile\n' "$token" > /etc/remotecompile/environment
|
||||
for key in JAVA_HOME ANDROID_HOME ANDROID_SDK_ROOT; do
|
||||
value=${!key:-}
|
||||
if [[ -n "$value" ]]; then
|
||||
[[ "$value" != *$'\n'* && "$value" != *'"'* && "$value" != *'\\'* ]] || { echo "Unsupported characters in $key" >&2; exit 1; }
|
||||
printf '%s="%s"\n' "$key" "$value" >> /etc/remotecompile/environment
|
||||
fi
|
||||
done
|
||||
fi
|
||||
chmod 0600 /etc/remotecompile/environment
|
||||
# Stop through systemd so existing workers can finish cancellation and persist state.
|
||||
systemctl stop remotecompile.service 2>/dev/null || true
|
||||
install -m 0755 "$binary" /opt/remotecompile/bin/remotecompile
|
||||
cat > /etc/systemd/system/remotecompile.service <<'UNIT'
|
||||
[Unit]
|
||||
Description=VibeCoding Android Remote Compilation
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=remotecompile
|
||||
Group=remotecompile
|
||||
WorkingDirectory=/var/lib/remotecompile
|
||||
EnvironmentFile=/etc/remotecompile/environment
|
||||
ExecStart=/opt/remotecompile/bin/remotecompile -listen 127.0.0.1:8765 -data /var/lib/remotecompile/data -tasks :app:assembleDebug
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
TimeoutStopSec=40
|
||||
KillMode=control-group
|
||||
UMask=0077
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectSystem=strict
|
||||
ProtectHome=true
|
||||
ReadWritePaths=/var/lib/remotecompile
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
UNIT
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now remotecompile.service
|
||||
for _ in {1..20}; do
|
||||
if systemctl is-active --quiet remotecompile.service; then
|
||||
if python3 - <<'PY'
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
config = Path('/etc/remotecompile/environment').read_text()
|
||||
token = next(line.split('=', 1)[1] for line in config.splitlines() if line.startswith('REMOTE_BUILD_TOKEN='))
|
||||
request = urllib.request.Request('http://127.0.0.1:8765/api/v1/health', headers={'Authorization': 'Bearer ' + token})
|
||||
with urllib.request.urlopen(request, timeout=2) as response:
|
||||
print('Health:', response.read().decode())
|
||||
PY
|
||||
then
|
||||
systemctl --no-pager --full status remotecompile.service
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
journalctl -u remotecompile.service --no-pager -n 30
|
||||
exit 1
|
||||
Reference in new issue
Block a user