this thing

This commit is contained in:
ldlda
2025-08-21 22:15:09 +07:00 Unverified
parent 6a335bb4c0
commit 402a9d401e
3 changed files with 78 additions and 16 deletions
+45
View File
@@ -0,0 +1,45 @@
#!/bin/sh
set -e
# 0th step from lda is to move the pre assed resolv.conf to the real resolv.conf
[ -f /tmp/resolv.conf ] && cp -af /tmp/resolv.conf /etc/resolv.conf || ([ -f /rom/etc/resolv.conf ] && cp -af /rom/etc/resolv.conf /etc/resolv.conf)
# 1. Fetch the latest version number from Tailscale's site
LATEST=$(curl -s https://pkgs.tailscale.com/stable/ | grep -Eo 'tailscale_[0-9\.]+_arm.tgz' | head -n1)
[ -z "$LATEST" ] && {
echo "❌ Couldn't find latest ARM binary."
exit 1
}
URL="https://pkgs.tailscale.com/stable/${LATEST}"
cd /var/tmp
[ -f "$LATEST" ] && {
echo "file exists"
rm "$LATEST"
}
echo "Downloading $LATEST..."
wget -q "$URL"
echo "got"
# 2. Extract binaries
# workaroubd
stripped=$(basename "$LATEST" .tgz)
tar xzf "$LATEST" --strip-components=1 "$stripped/tailscale" "$stripped/tailscaled"
echo "unzipped"
# 3. Install and set permissions
chmod +x tailscale tailscaled
mv tailscale tailscaled /usr/sbin/
# 4. Restart service
/etc/init.d/tailscale restart
# 5. Cleanup
rm "$LATEST"
echo "✅ Updated to $(tailscale version)"
+2 -16
View File
@@ -4,9 +4,10 @@ use tokio::{
io, io,
net::{TcpListener, UdpSocket}, net::{TcpListener, UdpSocket},
}; };
use axum::{Router, response::Html, routing::get}; use axum::{Router, response::Html, routing::get};
mod utils;
use utils::*;
async fn home() -> Html<&'static str> { async fn home() -> Html<&'static str> {
Html( Html(
r#" r#"
@@ -40,18 +41,3 @@ async fn main() -> color_eyre::Result<()> {
Ok(()) Ok(())
} }
async fn wake(_machine_name: &str) -> io::Result<()> {
let mac1 = [0x04, 0x7c, 0x16, 0x79, 0x6d, 0xee];
let mac2 = [0xbc, 0x09, 0x1b, 0xec, 0x65, 0xd0];
let suh = UdpSocket::bind("0.0.0.0:0").await?;
suh.set_broadcast(true)?;
for mac in [mac1, mac2] {
let pac: Vec<u8> = iter::once([0xff; 6])
.chain(iter::repeat_n(mac, 16))
.flatten()
.collect();
suh.send_to(&pac, "192.168.100.255:9").await?;
}
Ok(())
}
+31
View File
@@ -0,0 +1,31 @@
pub async fn wake(_machine_name: &str) -> io::Result<()> {
let mac1 = [0x04, 0x7c, 0x16, 0x79, 0x6d, 0xee];
let mac2 = [0xbc, 0x09, 0x1b, 0xec, 0x65, 0xd0];
let suh = UdpSocket::bind("0.0.0.0:0").await?;
suh.set_broadcast(true)?;
for mac in [mac1, mac2] {
let pac: Vec<u8> = iter::once([0xff; 6])
.chain(iter::repeat_n(mac, 16))
.flatten()
.collect();
suh.send_to(&pac, "192.168.100.255:9").await?;
}
Ok(())
}
use std::{iter, time::Duration};
use tokio::{
io,
net::{TcpStream, ToSocketAddrs, UdpSocket},
time::timeout,
};
/// generic so you can do "123.45.67.89:22" as an input
pub async fn ping_ip<T: ToSocketAddrs>(addr: T) -> bool {
// thanks cahtgpt
timeout(Duration::from_secs(1), TcpStream::connect(addr))
.await
.is_ok()
}