From a39f6ac0abc45fef780d46ab8e56d5cf55039846 Mon Sep 17 00:00:00 2001
From: root <root@sdvdbodsql01.slub-dresden.de>
Date: Mon, 8 Aug 2022 12:32:57 +0200
Subject: [PATCH] Add updater and update logic to install script.

---
 install.sh |  7 +++++++
 update.sh  | 21 +++++++++++++++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 update.sh

diff --git a/install.sh b/install.sh
index 34dcd08..a4636fc 100644
--- a/install.sh
+++ b/install.sh
@@ -1,5 +1,6 @@
 #!/bin/bash
 
+# Check for correct repository path
 if [[ ! -d /opt/sql-backup ]];
 then
   echo "ERROR: Could not find sql-backup repository in /opt/sql-backup. Please clone git repository to the" \
@@ -9,12 +10,17 @@ else
   cd /opt/sql-backup
 fi
 
+# Update repository
+bash update.sh
+
+# Check if config.json exists; create from template if not
 if [[ ! -f ./config.json ]]
 then
   echo "WARN: No configuration file found. Creating one with default values from config_template.json."
   cp ./config_template.json ./config.json
 fi
 
+# Check for existing systemd unit and replace
 if [[ ! -f /etc/systemd/system/sql-backup.service ]];
 then
   echo "WARN: existing service file found. Overwriting."
@@ -27,4 +33,5 @@ then
 fi
 cp -r ./service-unit/sql-backup.timer /etc/systemd/system
 
+# enable systemd unit
 systemctl enable sql-backup.service
diff --git a/update.sh b/update.sh
new file mode 100644
index 0000000..a8cf2c1
--- /dev/null
+++ b/update.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/bash
+#scriptroot=${BASH_SOURCE[0]}
+
+# create temporary directory in home
+mkdir -p ~/tmp
+
+# Switch to Application Directory
+cd /opt/sql-backup
+
+# save settings file
+cp config.json ~/tmp/
+
+# update git repository
+git stash
+git pull
+
+# restore settings file
+cp -f ~/tmp/config.json .
+
+# clear temporary directory
+rm -r ~/tmp/*
-- 
GitLab