diff --git a/orchestrating/README.org b/orchestrating/README.org index 6064ecd..059e37d 100644 --- a/orchestrating/README.org +++ b/orchestrating/README.org @@ -1,19 +1,45 @@ #+OPTIONS: toc:nil -* ROOT SERVICES +* INIT SYSTEM + +** ROOT SERVICES (Currently none!) =.sh= to be symlinked to =/etc/init.d/podman-containers= -* USER SERVICES AND RUNLEVELS +** USER SERVICES AND RUNLEVELS =.config= folder to be symlinked to =~= -* XDG VARIABLES AND RUNNING USER SERVICES ON LOGIN +** * XDG VARIABLES AND RUNNING USER SERVICES ON LOGIN =.profile= to be symlinked to =/home/$USER/.profile= -* RUN USERS SERVICES ON BOOT +** RUN USERS SERVICES ON BOOT Symlink =/etc/init.d/user= to =/etc/init.d/user.$usernames=. After add, add the latter service with =rc-update= as root. -* IF HAS PASSWORD +** IF HAS PASSWORD Add the following to a new file in =/etc/doas.d/=: #+begin_src shell permit nopass as permit nopass root as #+end_src + +* Timed cron jobs + +First, swap built-in =crond= for =dcron=. We need to swap cron binaries since we would have to give setgid capabilites to the whole Busybox binary to use the included cron binary, for which we also need to install =libcap=: + +#+begin_src shell + # apk add dcron libcap + ,** if crond is set up, remember to stop and delete it before continuing! + # rc-service dcron start + # rc-update add dcron + # setcap cap_setgid=ep /usr/sbin/crond +#+end_src + +After this, remember to add =root= and =$USER= to the =cron= group! + +We now set up =$USER='s crontab as such: + +#+begin_src shell + #crontab -u $USER -e + + @weekly ID=git-back.weekly /home/$user/pihanepi/orchestrating/cronjobs/forgejo-clone/forgejo-clone.sh +#+end_src + +Finally, check =/var/log/messages= to confirm everything ran successfully. diff --git a/orchestrating/cronjobs/forgejo-clone/forgejo-clone.sh b/orchestrating/cronjobs/forgejo-clone/forgejo-clone.sh index 1615a87..b97b07a 100755 --- a/orchestrating/cronjobs/forgejo-clone/forgejo-clone.sh +++ b/orchestrating/cronjobs/forgejo-clone/forgejo-clone.sh @@ -25,15 +25,15 @@ echo $repo_urls echo "----\n" #Cloning each repo to destdir -i=0; -finished=false; -while ! $finished +repo_idx=0; +repo_finished=false; +while ! $repo_finished do - i=$(($i+1)); - repo=$(awk "{print \$$i}" <(echo $repo_urls)) + repo_idx=$(($repo_idx+1)); + repo=$(awk "{print \$$repo_idx}" <(echo $repo_urls)) if [ "$repo" = "" ] then - finished=true + repo_finished=true else #Retrieve repo name for folder repo_name="$(awk -F/ '{print $5}' <(echo $repo))" @@ -42,16 +42,31 @@ do #Remove quotes from user_username username=${user_username%\"} username=${username#\"} - #Clone repo - #TODO: what do if repo already exists? if it! + #Clone or rebase repo 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 + git -C "$REPO_DIR$repo_name" fetch -t --all + branch="$(git -C "$REPO_DIR$repo_name" branch | awk '{print $2}')" + git -C "$REPO_DIR$repo_name" rebase $branch --onto origin/$branch else - git clone https://$user_username:$AUTH_TOKEN@$GIT_DOMAIN/$username/$repo_name /home/$USER/pihanepi/datamount/gitbackup/$repo_name --recurse-submodules + git clone https://$user_username:$AUTH_TOKEN@$GIT_DOMAIN/$username/$repo_name /home/$USER/pihanepi/datamount/gitbackup/$repo_name --recurse-submodules fi fi done +#NOTE: Cool git formatting and same loop to operate on all remote branches +#branches="$(git -C $REPO_DIR$repo_name branch -r --format='%(refname:short)' | awk -F/ '{if ($2) print $2;}')" +#branch_idx=0; +#branch_finished=false; +#while ! $branch_finished +#do +# branch_idx=$(($branch_idx+1)); +# branch=$(awk "{print \$$branch_idx}" <(echo $branches)) +# if [ "$branch" = "" ] +# then +# branch_finished=true +# else +# git -C "$REPO_DIR$repo_name" rebase $branch --onto origin/$branch +# fi +#done