From 5f3e105d234caf0c378bfcd571d63e0d4c87684f Mon Sep 17 00:00:00 2001 From: Attila Kovacs Date: Sat, 14 Sep 2024 23:11:55 +0200 Subject: [PATCH] Add Github Actions CI --- .github/dependabot.yml | 11 ++++++ .github/workflows/test.yml | 26 +++++++++++++ install.sh | 75 ++++++++++++++++++++++++++++---------- smax-scripts.service | 3 +- 4 files changed, 93 insertions(+), 22 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..6867e71 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file + +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..7b4dd8d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,26 @@ +name: Test installer + +on: + push: + paths: + - '*.sh' + - 'lua/**' + - 'smax-scripts.service' + - '.github/workflows/test.yml' + +jobs: + + test: + name: Test on Ubuntu + + runs-on: ubuntu-latest + steps: + - name: install redis + run: sudo apt install redis + + - name: Check out smax-server + uses: actions/checkout@v4 + + - name: Run installer + run: sudo ./install.sh auto + diff --git a/install.sh b/install.sh index 2a8d33e..f57b10a 100755 --- a/install.sh +++ b/install.sh @@ -11,61 +11,96 @@ # 09/14/2024 # -if [ $EUID -ne 0 ] - then echo "Please run as root" +if [ $EUID -ne 0 ] ; then + echo "Please run as root" exit 1 fi -# You can configure DESTDIR before calling this script to install to a location other -# than /usr (e.g. /usr/local or /opt). if [ "$DESTDIR" == "" ] ; then DESTDIR="/usr" fi # Create /usr/share/smax and its lua/ sub-directory -SMAX="$(DESTDIR)/share/smax" +SMAX="$DESTDIR/share/smax" # Copy LUA script over to /usr/share/smax -mkdir -p $SMAX/lua || exit 1 -cp -a lua $SMAX || exit 2 +echo ". Creating $SMAX/lua directory" +mkdir -p $SMAX/lua || exit 2 + +echo ". Copying LUA scripts to $SMAX/lua" +install -m 644 -D lua/* $SMAX/lua/ || exit 3 # install script loader and systemd unit file -install -m 755 smax-init.sh /usr/bin/ || ( exho exit 3 -install -m 644 smax-scripts.service /etc/systemd/system/ || exit 4 +echo ". Copying script loader to $DESTDIR/bin" +install -m 755 smax-init.sh $DESTDIR/bin/ || echo exit 4 + +echo ". Setting DESTDIR in script loader" +sed -i "s:/usr:$DESTDIR:g" $DESTDIR/bin/smax-init.sh || exit 6 + +echo ". Copying script loader to /etc/systemd/system" +install -m 644 smax-scripts.service /etc/systemd/system/ || exit 5 + +echo ". Setting DESTDIR in systemd unit" +sed -i "s:/usr:$DESTDIR:g" /etc/systemd/system/smax-scripts.service || exit 6 # Register smax-scripts with systemd -systemctl daemon-reload || exit 5 +echo ". Reloading systemd daemon" +systemctl daemon-reload || exit 7 + +# On some distros the service is redis, on others is redis-server... +REDIS=redis +if [ ! -e /lib/systemd/system/$REDIS ] ; then + REDIS=redis-server +fi # if you call the script with a single argument 'auto', then it will install # a default without asking any questions. (Without the option, the installer # will ask you to make some choices.) if [ "$1" == "auto" ] ; then - # automatic installation + # automatic installation + echo "Automatic installation..." - sed -i '/^.*BEGIN SMA.*/,/^.*END SMA.*$/d' *.lua || exit 6 - systemctl restart smax-scripts || exit 7 - systemctl enable redis || exit 8 - systemctl enable smax-scripts || exit 9 + echo ". Removing SMA-specific sections from scripts" + sed -i '/^.*BEGIN SMA.*/,/^.*END SMA.*/d' $SMAX/lua/*.lua || exit 8 + + echo ". Starting smax-scripts service" + systemctl restart smax-scripts + + journalctl -xeu smax-scripts.service + + echo ". Enabling Redis at boot" + systemctl enable $REDIS || exit 10 + + echo ". Enabling SMA-X at boot" + systemctl enable smax-scripts || exit 11 else # prompt for choices + echo "Manual installation..." - read -p "Are you going to use SMA-X at the SMA? " -n 1 -r + read -p "Are you going to use SMA-X outside of the SMA? " -n 1 -r echo # (optional) move to a new line if [[ $REPLY =~ ^[Yy]$ ]] ; then - sed -i '/^.*BEGIN SMA.*/,/^.*END SMA.*$/d' *.lua || exit 10 + echo ". Removing SMA-specific sections from scripts" + sed -i '/^.*BEGIN SMA.*/,/^.*END SMA.*$/d' *.lua || exit 12 fi read -p "start redis with SMA-X scripts at this time? " -n 1 -r echo # (optional) move to a new line if [[ $REPLY =~ ^[Yy]$ ]] ; then - systemctl restart smax-scripts || exit 11 + echo ". Starting smax-scripts service" + systemctl restart smax-scripts || exit 13 fi read -p "Enable and start SMA-X at boot time? " -n 1 -r echo # (optional) move to a new line if [[ $REPLY =~ ^[Yy]$ ]] ; then - systemctl enable redis || exit 12 - systemctl enable smax-scripts || exit 13 + echo ". Enabling Redis at boot" + systemctl enable $REDIS || exit 14 + + echo ". Enabling SMA-X at boot" + systemctl enable smax-scripts || exit 15 fi fi + +echo "Done!" diff --git a/smax-scripts.service b/smax-scripts.service index fa66942..1cb2982 100644 --- a/smax-scripts.service +++ b/smax-scripts.service @@ -5,8 +5,7 @@ After=redis.service [Service] Type=oneshot -WorkingDirectory=/usr/share/smax -ExecStart=/usr/sbin/smax-init.sh +ExecStart=/usr/bin/smax-init.sh RemainAfterExit=yes [Install]