From 670dd1fc85bb17e981dc4da3852e5447f442ffd5 Mon Sep 17 00:00:00 2001 From: Hane Date: Mon, 1 Jun 2026 17:09:27 +0200 Subject: [PATCH 1/2] fix: change doas with (proper) command_user explaination: https://www.redhat.com/en/blog/sudo-rootless-podman --- orchestrating/.config/rc/init.d/podman-containers | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/orchestrating/.config/rc/init.d/podman-containers b/orchestrating/.config/rc/init.d/podman-containers index bb39475..609c5c1 100755 --- a/orchestrating/.config/rc/init.d/podman-containers +++ b/orchestrating/.config/rc/init.d/podman-containers @@ -14,7 +14,9 @@ command="$PODMAN" command_args="start --all --filter restart-policy=always" name="podman-containers" command_background=true +command_user=hane pidfile="/var/run/${RC_SVCNAME}.pid" +#pidfile="/tmp/xdg/$UID-xdg-runtime-dir/${RC_SVCNAME}.pid" output_log="/home/${CONTAINER_USER:-$DEFAULT_CONTAINER_USER}/pihanepi/orchestrating/${RC_SVCNAME}.log" error_log="/home/${CONTAINER_USER:-$DEFAULT_CONTAINER_USER}/pihanepi/orchestrating/${RC_SVCNAME}.err" @@ -25,18 +27,18 @@ error_log="/home/${CONTAINER_USER:-$DEFAULT_CONTAINER_USER}/pihanepi/orchestrati start() { ebegin "Starting Podman containers with restart policy" - doas -u "$CONTAINER_USER" "$PODMAN" start --all --filter restart-policy=$RESTART_POLICY + "$PODMAN" start --all --filter restart-policy=$RESTART_POLICY eend $? } stop() { ebegin "Stopping Podman containers with restart policy" - CONTAINERS=$(doas -u "$CONTAINER_USER" "$PODMAN" container ls --filter restart-policy=$RESTART_POLICY -q) + CONTAINERS=$("$PODMAN" container ls --filter restart-policy=$RESTART_POLICY -q) if [ -n "$CONTAINERS" ]; then for CONTAINER in $CONTAINERS; do - doas -u "$CONTAINER_USER" "$PODMAN" stop "$CONTAINER" + "$PODMAN" stop "$CONTAINER" done eend $? else From a2e088438360ea602ae92637d7d907bb916522a9 Mon Sep 17 00:00:00 2001 From: Hane Date: Wed, 3 Jun 2026 23:04:34 +0200 Subject: [PATCH 2/2] wip: auto repo local copy via cronjob --- datamount/gitbackup/this-is-git-dir.txt | 0 orchestrating/cronjobs/README.org | 1 + .../cronjobs/forgejo-clone/forgejo-clone.sh | 57 +++++++++++++++++++ orchestrating/cronjobs/forgejo-clone/secrets | 3 + 4 files changed, 61 insertions(+) create mode 100644 datamount/gitbackup/this-is-git-dir.txt create mode 100644 orchestrating/cronjobs/README.org create mode 100755 orchestrating/cronjobs/forgejo-clone/forgejo-clone.sh create mode 100644 orchestrating/cronjobs/forgejo-clone/secrets diff --git a/datamount/gitbackup/this-is-git-dir.txt b/datamount/gitbackup/this-is-git-dir.txt new file mode 100644 index 0000000..e69de29 diff --git a/orchestrating/cronjobs/README.org b/orchestrating/cronjobs/README.org new file mode 100644 index 0000000..6f040e0 --- /dev/null +++ b/orchestrating/cronjobs/README.org @@ -0,0 +1 @@ +Make sure crond is running, and add each script to the user's crontab diff --git a/orchestrating/cronjobs/forgejo-clone/forgejo-clone.sh b/orchestrating/cronjobs/forgejo-clone/forgejo-clone.sh new file mode 100755 index 0000000..1615a87 --- /dev/null +++ b/orchestrating/cronjobs/forgejo-clone/forgejo-clone.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env sh + +. secrets +#TODO check secrets file exists + +#Retrieve token user +user_json=$(curl -s -X 'GET' \ +'https://$GIT_DOMAIN/api/v1/user' \ +-H 'accept: application/json' \ +-H "Authorization: token ${AUTH_TOKEN}") + +user_id=$(jq ".id" <(echo "$user_json")) +user_username=$(jq ".username" <(echo "$user_json")) +echo $user_username + +#Retrieve repos from user, including private repos +repo_json=$(curl -s -X 'GET' \ + "https://$GIT_DOMAIN/api/v1/repos/search?uid=${user_id}?private=true" \ + -H 'accept: application/json' \ + -H "Authorization: token ${AUTH_TOKEN}") + +#Listing only the HTTPS repo clone URL +repo_urls=$(jq ".data" <(echo "$repo_json") | jq ".[] | .html_url" | grep Hane) +echo $repo_urls +echo "----\n" + +#Cloning each repo to destdir +i=0; +finished=false; +while ! $finished +do + i=$(($i+1)); + repo=$(awk "{print \$$i}" <(echo $repo_urls)) + if [ "$repo" = "" ] + then + finished=true + else + #Retrieve repo name for folder + repo_name="$(awk -F/ '{print $5}' <(echo $repo))" + repo_name="${repo_name%\"}" + #echo $repo_name + #Remove quotes from user_username + username=${user_username%\"} + username=${username#\"} + #Clone repo + #TODO: what do if repo already exists? if it! + if [ -e "$REPO_DIR$repo_name" ] + then + echo "REPO: $repo_name" + git -C "$REPO_DIR$repo_name" fetch --all + #git -C "$REPO_DIR$repo_name" rebase --update-refs + else + git clone https://$user_username:$AUTH_TOKEN@$GIT_DOMAIN/$username/$repo_name /home/$USER/pihanepi/datamount/gitbackup/$repo_name --recurse-submodules + fi + fi +done + diff --git a/orchestrating/cronjobs/forgejo-clone/secrets b/orchestrating/cronjobs/forgejo-clone/secrets new file mode 100644 index 0000000..194b4ad --- /dev/null +++ b/orchestrating/cronjobs/forgejo-clone/secrets @@ -0,0 +1,3 @@ +REPO_DIR=/home/$USER/pihanepi/datamount/gitbackup/ +GIT_DOMAIN=git.roboces.dev +AUTH_TOKEN=