more bullshit IN!

This commit is contained in:
lda
2025-08-26 21:47:52 +07:00 Unverified
parent 7371d2ae8c
commit 9de286f59b
22 changed files with 845 additions and 122 deletions
+3
View File
@@ -37,6 +37,9 @@ WAKEY_HOST=git.ldlda.com WAKEY_OWNER=lda WAKEY_REPO=wakey sh /etc/ldlda_help/upd
## Scripts overview
- `act_runner.ps1` — Start/seed the local Gitea runner. Use `-Attach` to see logs, `-ForceConfigure` to register non-interactively.
- `dev_push.ps1` — Fast dev loop: build + upload to router. Usage:
- `./scripts/dev_push.ps1 -Pass <password> [-HostName <ip>] [-RemotePath </root/.bin/wakey>] [-Restart] [-Quiet]`
- Uploads to `<RemotePath>.tmp` then atomically moves into place; `-Restart` restarts the service; `-Quiet` silences MOTD.
- `cross_build.ps1` — Simple wrapper for `cargo build` per target (default: armv7-unknown-linux-musleabihf).
- `package_rootfs.ps1` — Produces `dist/wakey-rootfs-<version>-<target>.tgz` with `/root/.bin/wakey` and `/etc/init.d/*`.
- `package.ps1` — Dev bundle with binaries + init scripts (not a rootfs layout).
+157
View File
@@ -0,0 +1,157 @@
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSAvoidDefaultValueSwitchParameter', 'Default true is intentional for fast dev loop')]
param(
[string]$Pass,
[string]$HostName = "192.168.100.1",
[string]$User = "root",
[string]$RemotePath = "/root/.bin/wakey",
[string]$Target = "armv7-unknown-linux-musleabihf",
[string]$BinName = "wakey",
[string]$HostKey,
[switch]$Restart = $true,
[switch]$Quiet = $true
)
$ErrorActionPreference = 'Stop'
try { $PSStyle.OutputRendering = 'Host' } catch {}
function Invoke-Ext {
param(
[Parameter(Mandatory = $true)][string]$Exe,
[Parameter(Mandatory = $true)][string[]]$Args,
[Parameter(Mandatory = $true)][string]$Label
)
$displayArgs = @($Args)
for ($i = 0; $i -lt $displayArgs.Count; $i++) {
if ($displayArgs[$i] -eq '-pw' -and ($i + 1) -lt $displayArgs.Count) { $displayArgs[$i + 1] = '****' } # lowkey leaked my password
}
Write-Host ("[{0}] {1} {2}" -f $Label, $Exe, ($displayArgs -join ' ')) -ForegroundColor Cyan
$out = & $Exe @Args 2>&1
$code = $LASTEXITCODE
if ($code -ne 0) {
Write-Error ("{0} failed ({1}):`n{2}" -f $Label, $code, ($out -join "`n"))
throw ("{0} failed ({1})" -f $Label, $code)
}
return $out
}
$repoRoot = Split-Path -Parent $PSScriptRoot
Push-Location $repoRoot
try {
Write-Host "[build] cargo build --release --target $Target" -ForegroundColor Cyan
cargo build --release --target $Target
if ($LASTEXITCODE -ne 0) { throw "cargo build failed ($LASTEXITCODE)" }
$local = Join-Path $repoRoot ("target/" + $Target + "/release/" + $BinName)
if (-not (Test-Path $local)) { throw "binary not found: $local" }
$remoteTmp = "$RemotePath.tmp"
$destTmp = "{0}@{1}:{2}" -f $User, $HostName, $remoteTmp
$localDeploy = Join-Path $repoRoot 'scripts/remote_deploy_wakey.sh'
$deployTmp = '/var/tmp/remote_deploy_wakey.sh'
$destDeployTmp = "{0}@{1}:{2}" -f $User, $HostName, $deployTmp
$deployPreferred = '/root/.bin/remote_deploy_wakey.sh'
if ($Pass) {
$pscp = Get-Command pscp.exe -ErrorAction SilentlyContinue
if ($pscp) {
$pscpArgs = @()
if ($Quiet) { $pscpArgs += '-q' }
if ($HostKey) { $pscpArgs += @('-batch', '-scp', '-hostkey', $HostKey, '-pw', $Pass, $local, $destTmp) }
else { $pscpArgs += @('-scp', '-pw', $Pass, $local, $destTmp) }
Invoke-Ext -Exe $pscp.Path -Args $pscpArgs -Label 'push'
$plink = Get-Command plink.exe -ErrorAction SilentlyContinue
if (Test-Path $localDeploy) {
$pscpArgsD = @()
if ($Quiet) { $pscpArgsD += '-q' }
if ($HostKey) { $pscpArgsD += @('-batch', '-scp', '-hostkey', $HostKey, '-pw', $Pass, $localDeploy, $destDeployTmp) }
else { $pscpArgsD += @('-scp', '-pw', $Pass, $localDeploy, $destDeployTmp) }
Invoke-Ext -Exe $pscp.Path -Args $pscpArgsD -Label 'push-deploy'
}
$remoteCmdCore = @'
DEPLOY=$DEPLOY_PREFERRED
if [ ! -x "$DEPLOY" ] && [ -f $DEPLOY_TMP ]; then
sed -i "s/\r$//" $DEPLOY_TMP 2>/dev/null || true
chmod +x $DEPLOY_TMP; DEPLOY=$DEPLOY_TMP
fi
sh "$DEPLOY" $REMOTE_TMP $REMOTE_PATH $DO_RESTART
'@
$remoteCmdCore = $remoteCmdCore.Replace('$DEPLOY_PREFERRED', $deployPreferred).Replace('$DEPLOY_TMP', $deployTmp).Replace('$REMOTE_TMP', $remoteTmp).Replace('$REMOTE_PATH', $RemotePath)
$remoteCmdCore = if ($Restart) { $remoteCmdCore.Replace('$DO_RESTART', '1') } else { $remoteCmdCore.Replace('$DO_RESTART', '0') }
$remoteCmdCore = ($remoteCmdCore -replace "`r", "")
$remoteCmd = "sh -lc '$remoteCmdCore'"
if ($Quiet) { $remoteCmd = "$remoteCmd >/dev/null 2>&1" }
if ($plink) {
$plinkArgs = @('-batch', '-ssh', '-pw', $Pass, "$User@$HostName", $remoteCmd)
Invoke-Ext -Exe $plink.Path -Args $plinkArgs -Label 'ssh'
}
else {
$sshArgs = @()
if ($Quiet) { $sshArgs += '-q' }
$sshArgs += @("$User@$HostName", $remoteCmd)
Invoke-Ext -Exe 'ssh' -Args $sshArgs -Label 'ssh'
}
}
else {
Write-Warning "pscp.exe not found. Falling back to scp (you may be prompted for a password)."
$scpArgs = @('-O')
if ($Quiet) { $scpArgs += '-q' }
$scpArgs += @($local, $destTmp)
Invoke-Ext -Exe 'scp' -Args $scpArgs -Label 'push'
if (Test-Path $localDeploy) {
$scpArgsD = @('-O')
if ($Quiet) { $scpArgsD += '-q' }
$scpArgsD += @($localDeploy, $destDeployTmp)
Invoke-Ext -Exe 'scp' -Args $scpArgsD -Label 'push-deploy'
}
$remoteCmdCore = @'
DEPLOY=$DEPLOY_PREFERRED
if [ ! -x "$DEPLOY" ] && [ -f $DEPLOY_TMP ]; then
sed -i "s/\r$//" $DEPLOY_TMP 2>/dev/null || true
chmod +x $DEPLOY_TMP; DEPLOY=$DEPLOY_TMP
fi
sh "$DEPLOY" $REMOTE_TMP $REMOTE_PATH $DO_RESTART
'@
$remoteCmdCore = $remoteCmdCore.Replace('$DEPLOY_PREFERRED', $deployPreferred).Replace('$DEPLOY_TMP', $deployTmp).Replace('$REMOTE_TMP', $remoteTmp).Replace('$REMOTE_PATH', $RemotePath)
$remoteCmdCore = if ($Restart) { $remoteCmdCore.Replace('$DO_RESTART', '1') } else { $remoteCmdCore.Replace('$DO_RESTART', '0') }
$remoteCmdCore = ($remoteCmdCore -replace "`r", "")
$remoteCmd = "sh -lc '$remoteCmdCore'"
if ($Quiet) { $remoteCmd = "$remoteCmd >/dev/null 2>&1" }
$sshArgs = @()
if ($Quiet) { $sshArgs += '-q' }
$sshArgs += @("$User@$HostName", $remoteCmd)
Invoke-Ext -Exe 'ssh' -Args $sshArgs -Label 'ssh'
}
}
else {
$scpArgs = @('-O')
if ($Quiet) { $scpArgs += '-q' }
$scpArgs += @($local, $destTmp)
Invoke-Ext -Exe 'scp' -Args $scpArgs -Label 'push'
if (Test-Path $localDeploy) {
$scpArgsD = @('-O')
if ($Quiet) { $scpArgsD += '-q' }
$scpArgsD += @($localDeploy, $destDeployTmp)
Invoke-Ext -Exe 'scp' -Args $scpArgsD -Label 'push-deploy'
}
$remoteCmdCore = @'
DEPLOY=$DEPLOY_PREFERRED
if [ ! -x "$DEPLOY" ] && [ -f $DEPLOY_TMP ]; then sed -i "s/\r$//" $DEPLOY_TMP 2>/dev/null || true; chmod +x $DEPLOY_TMP; DEPLOY=$DEPLOY_TMP; fi
sh "$DEPLOY" $REMOTE_TMP $REMOTE_PATH $DO_RESTART
'@
$remoteCmdCore = $remoteCmdCore.Replace('$DEPLOY_PREFERRED', $deployPreferred).Replace('$DEPLOY_TMP', $deployTmp).Replace('$REMOTE_TMP', $remoteTmp).Replace('$REMOTE_PATH', $RemotePath)
$remoteCmdCore = if ($Restart) { $remoteCmdCore.Replace('$DO_RESTART', '1') } else { $remoteCmdCore.Replace('$DO_RESTART', '0') }
$remoteCmdCore = ($remoteCmdCore -replace "`r", "")
$remoteCmd = "sh -lc '$remoteCmdCore'"
if ($Quiet) { $remoteCmd = "$remoteCmd >/dev/null 2>&1" }
$sshArgs = @()
if ($Quiet) { $sshArgs += '-q' }
$sshArgs += @("$User@$HostName", $remoteCmd)
Invoke-Ext -Exe 'ssh' -Args $sshArgs -Label 'ssh'
}
Write-Host "done ✔" -ForegroundColor Green
}
finally {
Pop-Location
}
+6
View File
@@ -15,3 +15,9 @@ start_service() {
stop_service() {
: # one-shot
}
# Test manually:
# chmod +x /etc/init.d/update_wakey
# /etc/init.d/update_wakey start
# Or enable on boot:
# /etc/init.d/update_wakey enable
+1 -1
View File
@@ -15,7 +15,7 @@ fi
kill -TERM "$pids" 2>/dev/null || true
# Optional: hard kill if still alive after a short grace
sleep 1 # uhhh sleep is stupid
usleep 250000 # uhhh sleep is stupid
remain=""
for p in $pids; do
kill -0 "$p" 2>/dev/null && remain="$remain $p"
+26 -4
View File
@@ -16,7 +16,9 @@
set -eu
ARCH=${WAKEY_ARCH:-armv7-unknown-linux-musleabihf}
TMPFILE="/tmp/wakey-rootfs.$$.$ARCH.tgz"
TMPDIR="/var/tmp"
TMPFILE="$TMPDIR/wakey-rootfs.$$.$ARCH.tgz"
STAGING="$TMPDIR/wakey-rootfs.$$.$ARCH"
log() { echo "[update_wakey] $*"; }
fail() { echo "[update_wakey] ERROR: $*" >&2; exit 1; }
@@ -90,12 +92,32 @@ main() {
fi
log "installing"
tar -xz -f "$TMPFILE" -C / || fail "extract failed"
mkdir -p "$TMPDIR" "$STAGING"
tar -xz -f "$TMPFILE" -C "$STAGING" || fail "extract failed"
# Ensure execute bits on staged files we know should be executable
for f in \
"$STAGING/etc/init.d/"* \
"$STAGING/etc/ldlda_help/"*.sh \
"$STAGING/root/.bin/wakey" \
"$STAGING/root/.bin/kill_wakey.sh"; do
[ -e "$f" ] && chmod +x "$f" 2>/dev/null || true
done
# Normalize line endings for shell scripts (avoid CRLF issues on OpenWrt)
for f in \
"$STAGING/etc/init.d/"* \
"$STAGING/etc/ldlda_help/"*.sh; do
[ -f "$f" ] && sed -i 's/\r$//' "$f" 2>/dev/null || true
done
# Copy staged tree into /
tar -C "$STAGING" -cf - . | tar -C / -xpf - || fail "install copy failed"
rm -f "$TMPFILE"
rm -rf "$STAGING"
if [ -f /etc/init.d/wakey ]; then
chmod +x /etc/init.d/wakey || true
chmod +x /etc/init.d/kill_wakey.sh || true
/etc/init.d/wakey enable || true
/etc/init.d/wakey restart || /etc/init.d/wakey start || true
fi
+37 -6
View File
@@ -6,7 +6,8 @@
param(
[Parameter(Mandatory = $true)][string]$Version,
[Parameter(Mandatory = $true)][string]$Target,
[string]$OutDir = "dist"
[string]$OutDir = "dist",
[switch]$NoBin
)
$ErrorActionPreference = 'Stop'
@@ -17,7 +18,6 @@ New-Item -ItemType Directory -Force -Path $dist | Out-Null
$binName = if ($Target -like "*-windows-*") { "wakey.exe" } else { "wakey" }
$binSrc = Join-Path $root "target/$Target/release/$binName"
if (-not (Test-Path $binSrc)) { throw "Missing binary: $binSrc (build it first)" }
$staging = Join-Path $dist ("rootfs-" + [System.Guid]::NewGuid().ToString("N"))
New-Item -ItemType Directory -Force -Path $staging | Out-Null
@@ -28,13 +28,37 @@ $etcDir = Join-Path $staging "etc/init.d"
New-Item -ItemType Directory -Force -Path $rootDir | Out-Null
New-Item -ItemType Directory -Force -Path $etcDir | Out-Null
Copy-Item $binSrc (Join-Path $rootDir "wakey") -Force
Copy-Item (Join-Path $root 'scripts/kill.sh') (Join-Path $rootDir "kill_wakey.sh") -Force
if (-not $NoBin) {
if (Test-Path $binSrc) {
Copy-Item $binSrc (Join-Path $rootDir "wakey") -Force
}
else {
throw "Missing binary: $binSrc (build it first or pass -NoBin)"
}
}
# Normalize kill script line endings and copy
$killSrc = Join-Path $root 'scripts/kill_wakey.sh'
if (Test-Path $killSrc) {
$killContent = Get-Content -Raw -LiteralPath $killSrc
$killContent = $killContent -replace "`r`n", "`n"
Set-Content -NoNewline -LiteralPath (Join-Path $rootDir "kill_wakey.sh") -Value $killContent -Encoding UTF8
}
# Normalize remote deploy script and copy (optional helper)
$deploySrc = Join-Path $root 'scripts/remote_deploy_wakey.sh'
if (Test-Path $deploySrc) {
$deployContent = Get-Content -Raw -LiteralPath $deploySrc
$deployContent = $deployContent -replace "`r`n", "`n"
Set-Content -NoNewline -LiteralPath (Join-Path $rootDir "remote_deploy_wakey.sh") -Value $deployContent -Encoding UTF8
}
# Copy all OpenWrt init scripts present in repo
Get-ChildItem (Join-Path $root 'scripts/init/openwrt') -File | ForEach-Object {
$dest = Join-Path $etcDir $_.Name
Copy-Item $_.FullName $dest -Force
$content = Get-Content -Raw -LiteralPath $_.FullName
# normalize to LF line endings
$content = $content -replace "`r`n", "`n"
Set-Content -NoNewline -LiteralPath $dest -Value $content -Encoding UTF8
}
# Copy helper scripts intended for /etc/ldlda_help
@@ -43,7 +67,10 @@ if (Test-Path $helpSrc) {
$etcHelpDir = Join-Path $staging 'etc/ldlda_help'
New-Item -ItemType Directory -Force -Path $etcHelpDir | Out-Null
Get-ChildItem $helpSrc -File | ForEach-Object {
Copy-Item $_.FullName (Join-Path $etcHelpDir $_.Name) -Force
$d = Join-Path $etcHelpDir $_.Name
$c = Get-Content -Raw -LiteralPath $_.FullName
$c = $c -replace "`r`n", "`n"
Set-Content -NoNewline -LiteralPath $d -Value $c -Encoding UTF8
}
}
@@ -65,5 +92,9 @@ Remove-Item -Recurse -Force $staging
Write-Host "Rootfs package: " (Join-Path $dist $pkgName)
Write-Host "On router: wget -O- <URL/$pkgName> | tar -xz -C /"
Write-Host "Then: chmod +x /etc/init.d/wakey && /etc/init.d/wakey enable && /etc/init.d/wakey start"
if ($NoBin) {
Write-Host "Note: -NoBin used, binary not included. Only scripts/configs were packaged." -ForegroundColor Yellow
}
Write-Host "Helper scripts: /etc/ldlda_help/* (e.g., update_wakey.sh, update_tailscale.sh). Mark executable if needed: chmod +x /etc/ldlda_help/*.sh"
Write-Host "Kill helper: /root/.bin/kill_wakey.sh (make it executable: chmod +x /root/.bin/kill_wakey.sh)"
<# if (Test-Path $deploySrc) { #> Write-Host "Deploy helper: /root/.bin/remote_deploy_wakey.sh (chmod +x /root/.bin/remote_deploy_wakey.sh)" # }
+38
View File
@@ -0,0 +1,38 @@
#!/bin/sh
# Usage: remote_deploy_wakey.sh <bin_tmp> <dest_path> [restart_flag]
# restart_flag: 1 (default) to stop/start, 0 to only replace file.
set -e
BIN_TMP="$1"
DEST="$2"
RESTART="${3:-1}"
INIT="/etc/init.d/wakey"
KILL="/root/.bin/kill_wakey.sh"
if [ -z "$BIN_TMP" ] || [ -z "$DEST" ]; then
echo "usage: $0 <bin_tmp> <dest_path> [restart_flag]" >&2
exit 2
fi
[ -f "$BIN_TMP" ] || { echo "tmp binary not found: $BIN_TMP" >&2; exit 1; }
chmod +x "$BIN_TMP" || true
if [ "$RESTART" = "1" ]; then
if [ -x "$INIT" ]; then
"$INIT" stop || true
elif [ -x "$KILL" ]; then
sh "$KILL" || true
fi
fi
mv -f "$BIN_TMP" "$DEST"
if [ "$RESTART" = "1" ]; then
if [ -x "$INIT" ]; then
"$INIT" start || "$INIT" restart || true
else
nohup "$DEST" >/dev/null 2>&1 &
fi
fi
exit 0