From 2200957d4413cb9f46d08800b8fe51f88eed113e Mon Sep 17 00:00:00 2001 From: Bram Dingelstad Date: Mon, 29 Sep 2025 15:59:03 +0200 Subject: [PATCH] first commit (hi oxide folks :) --- caw.fish | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100755 caw.fish diff --git a/caw.fish b/caw.fish new file mode 100755 index 0000000..a1faca6 --- /dev/null +++ b/caw.fish @@ -0,0 +1,123 @@ +#!/usr/bin/fish + +if test "$argv[1]" = init + if test ! -f "./Cawfile" + echo "✨ Creating Cawfile..." + echo "# Cawfile, created $(date) +set server example.fowl +set app $(pwd | path basename) + +set ignore "" + +set local_build_command "" +set build_command "" +" >./Cawfile + else + echo "πŸ™…πŸ» Cawfile already created, not overwriting!" + end + return +end + +if test ! -f "$PWD/Cawfile" + echo "πŸ˜” No Cawfile found, exiting..." + return +end + +source "$PWD/Cawfile" + +if test "$server" = "" + echo "πŸ€” Server not set in Cawfile" + return +end + +if test "$app" = "" + echo "🧐 App not set in Cawfile" + return +end + +if test "$ignore" != "" + set ignore "|$ignore" +end + +function deploy + echo "🚚 Deploying $app on $server" + sleep 1 + + if test "$local_build_command" != "" + fish -c "$local_build_command" + end + + # Pre-ping server so we wake-up wireguard + ping $server -c 1 >/dev/null + # Pack up source code, but ignore common .git, target, .env and extra $ignore variable + # send to server and start building using cargo + tar zcf - (ls -a . | tail -n +3 | grep -vE ".git|target|.env|Cawfile$ignore") \ + | ssh $server " + $build_env + + mkdir -p /tmp/caw/$app + + cd /tmp/caw/$app && ls . | grep -v target | xargs rm -rf + + mkdir -p /usr/bin/caw + echo 'πŸ“¦οΈπŸ› οΈ Beginning unpacking & compilation' + tar zxvf - && $build_command + " + + # Pre-ping server so we wake-up wireguard + ping $server -c 1 >/dev/null + + # echo standard openrc config and send to server and start service and add to startup + echo "#!/sbin/openrc-run +supervisor=supervise-daemon + +name=$app +$env + +command=/usr/bin/caw/$app +command_user=$app:$app +command_background=true +output_log=\"/var/log/$app.log\" +error_log=\"/var/log/$app.log\" + +depend() { + need net localmount + after firewall + + touch /var/log/$app.log + chown $app:$app /var/log/$app.log +} + " | ssh $server " + cat - > /etc/init.d/$app + chmod +x /etc/init.d/$app + groupadd caw + useradd $app -G caw + rc-update add $app default + service $app restart + " +end + +if test "$argv[1]" = deploy + deploy +else if test "$argv[1]" = logs + ssh "$server" "tail -f /var/log/$app.log" +else if test "$argv[1]" = restart + ssh "$server" "service $app restart" +else if test "$argv[1]" = stop + ssh "$server" "service $app stop" +else if test "$argv[1]" = stats + ssh -t "$server" "htop -F '$app'" + +else + echo "πŸ¦β€β¬› caw - A small fly alternative, written in Fish, compatible with Alpine Linux + + deploy - 🚚 Deploy to server based on information in Cawfile + logs - πŸ“œ Tail the logs on the server + restart - πŸ’‘Restart the service on the server + stop - πŸ›‘ Stop the service on the server + stats - πŸ“ˆ Open htop on the app's server with filter for app + init - πŸ†• Create Cawfile in current directory, if not already available + +✨ Written by Bram Dingelstad (https://bram.dingelstad.works) + " +end