Skip to content

Commit

Permalink
Add Github Actions CI
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Sep 14, 2024
1 parent 06cbc05 commit 5f3e105
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 22 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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

75 changes: 55 additions & 20 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
3 changes: 1 addition & 2 deletions smax-scripts.service
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 5f3e105

Please sign in to comment.