Bachelor Tech
  • Home
  • Tutorials
  • Tips
  • Portfolio
  • About Jan
  • Contact Jan

8. GitOps – manage your shutdown scripts with Gitea

by Jan Bachelor October 28, 2025

In case you have a local instance of Gitea to manage version control of your scripts, apps and/or websites, you can also manage your scripts this way.

The idea is to have a copy of all the work in /opt and commit that to Gitea. We will create a simple deploy.sh script that can be used in the future if you download a newer version and want to deploy it from the otherwise passive git repo on /opt to the actual ‘live folders’.

IMPORTANT: Once implemented, you should not be making any changes directly to the live locations (such as under /etc/apcupsd) but within /opt and then using the deploy.sh script to copy them (for testing) before committing the changes locally and to your origin server.

  • Assuming that you have an instance of Gitea, you would need to make a copy of the scripts into one folder. The approach below will show you how – let’s utilize /opt for this purpose.
# Create a new folder
sudo mkdir -p /opt/ups-scripts

# Copy your existing scripts there
sudo cp /usr/local/sbin/ups_manager.sh /opt/ups-scripts
sudo cp /usr/local/sbin/push_ups_to_kuma.sh /opt/ups-scripts

# Copy the on & onbattery scripts to your new to-be-git managed folder
sudo cp /etc/apcupsd/onbattery /opt/ups-scripts
sudo cp /etc/apcupsd/offbattery /opt/ups-scripts
  • Create a deploy.sh script:
nano /opt/ups-scripts/deploy.sh

#!/bin/bash
#
# This script deploys all custom scripts from the /opt/ups-scripts (SOURCE)
# to their live (DESTINATION) locations.
#
# Run this script any time you make a change in the /opt/ups-scripts repo.
#
set -e # Exit immediately if any command fails

echo "Starting deployment of UPS scripts..."
SOURCE_DIR="/opt/ups-scripts"

# === LIVE LOCATIONS ===
DEST_CRON_SCRIPTS="/usr/local/sbin"
DEST_APC_SCRIPTS="/etc/apcupsd"

# --- 1. Deploy Cron/Sbin Scripts ---
echo "Deploying cron scripts to $DEST_CRON_SCRIPTS..."
sudo cp "$SOURCE_DIR/ups_manager.sh" "$DEST_CRON_SCRIPTS/ups_manager.sh"
sudo cp "$SOURCE_DIR/push_ups_to_kuma.sh" "$DEST_CRON_SCRIPTS/push_ups_to_kuma.sh"

# Ensure they are executable
sudo chmod +x "$DEST_CRON_SCRIPTS/ups_manager.sh"
sudo chmod +x "$DEST_CRON_SCRIPTS/push_ups_to_kuma.sh"

# --- 2. Deploy apcupsd Event Scripts ---
echo "Deploying apcupsd scripts to $DEST_APC_SCRIPTS..."
sudo cp "$SOURCE_DIR/onbattery" "$DEST_APC_SCRIPTS/onbattery"
sudo cp "$SOURCE_DIR/offbattery" "$DEST_APC_SCRIPTS/offbattery"

# Ensure they are executable
sudo chmod +x "$DEST_APC_SCRIPTS/onbattery"
sudo chmod +x "$DEST_APC_SCRIPTS/offbattery"

echo ""
echo "--------------------------------"
echo "Deployment successful!"
echo "Run 'git commit' and 'git push' to save your changes."
echo "--------------------------------"
  • Add them to Gitea
cd /opt/ups-scripts
sudo chown -R your_user:your_user .
git init
# In case your default branch is called 'master' rather than 'main'
git branch -m main
git add .
git commit -m "Initial commit of all UPS management scripts."
# You will need to create the repository on your Gitea server first
git remote add origin <http://your-gitea-server/your-user/ups-scripts.git>
git push -u origin main
A screenshot from Gitea showcasing the scripts being stored there for better source version control.
Our scripts are safely stored in Gitea
  • You might ask ‘why not to just symlink the live destinations, such as in /etc/apcupsd ? You totally could but what happens if you run a git pull and then have a conflict? On a production server that is time-sensitive to disruption, this could be an issue – for this reason, I recommend to follow the best practices from start. Enjoy!

Voila, all done! Just remember to following the GitOps method of deployment:

  1. Edit the files in /opt and then run the deploy.sh script.
  2. If you are happy with the changes, then commit them and push them.
  3. If you make changes to the repo in Gitea, then run git pull on your local instance and, once confirmed that it downloaded properly (no conflicts, etc.), then run the deploy.sh script again.
7. Add Wake-on-LAN to automatically wake up your hosts!
Go back to course overview: Automate Graceful Shutdown & Wake on LAN for Proxmox with RPi (APC)

Leave a Comment Cancel Reply

Save my name, email, and website in this browser for the next time I comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 FacebookWhatsappEmail

Course Steps

  1. 1. Automated Proxmox UPS Shutdown Process - Goals & Installation
  2. 2. Configure apcupsd, SSH keys and SMTP
  3. 3. Prepare a Script of Scripts for automated shutdown of Proxmox hosts
  4. 4. Prepare onbaterry and offbatery APC scripts
  5. 5. Bonus: Add UPS monitoring to Uptime Kuma
  6. 6. Run a UPS drain test!
  7. 7. Add Wake-on-LAN to automatically wake up your hosts!
  8. 8. GitOps - manage your shutdown scripts with Gitea

Other courses

Create an automated Gravity workflow that will allow...

January 19, 2024

Dynamically Populate Gravity Forms from Google Sheets (GSheets...

March 16, 2021

Concur Alternative: Import Employees’ Credit Card Expenses to...

January 19, 2024

Turn your Raspberry Pi into a Proxmox Backup...

July 13, 2025

Install iRedMail Mail Server As Proxmox VM With...

October 31, 2024

Recent Posts

  • How to get LXC containers for Proxmox outside of ready-made templates

  • How to join two Proxmox nodes into a cluster (PVE 8.x)

  • How to Rename a Proxmox Node

Facebook Twitter Instagram Pinterest Linkedin Youtube

All Rights Reserved. The theme was customized from Soledad, see PenciDesign

Bachelor Tech
  • Home
  • Tutorials
  • Tips
  • Portfolio
  • About Jan
  • Contact Jan