101 lines
2.5 KiB
Bash
Executable File
101 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
toolName=matrix-commander
|
|
toolCloneUrl='https://github.com/8go/matrix-commander.git'
|
|
toolDeps="python3-pip python3-venv libolm-dev"
|
|
toolVenvDir=
|
|
|
|
# Get script working directory
|
|
# (when called from a different directory)
|
|
WDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd)"
|
|
APTOPT=
|
|
CONFIG=0
|
|
SCRIPT_FILE=$(basename -- $0)
|
|
SCRIPT_NAME=${SCRIPT_FILE%%.*}
|
|
CONFIG_FILE_NAME="${SCRIPT_NAME}.cfg"
|
|
CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example"
|
|
|
|
step_config() {
|
|
## or to use sequencer api with global config file:
|
|
initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE"
|
|
|
|
if [ $? -eq 0 ] ; then
|
|
CONFIG=1
|
|
else
|
|
# End if no configuration file exists
|
|
[ $DRY -eq 0 ] && return -1
|
|
fi
|
|
|
|
toolVenvDir="$MACO_BASE_DIR"
|
|
|
|
## Apt cmdline option to suppress user interaction
|
|
[ $QUIET -ne 0 ] && APTOPT="-y"
|
|
|
|
## Return of non zero value will abort the sequence
|
|
return 0
|
|
}
|
|
|
|
|
|
step_1_info() { echo "Add system user"; }
|
|
step_1_alias() { ALIAS="install"; }
|
|
step_1() {
|
|
exe adduser --system $MACO_USER --group --home "${MACO_BASE_DIR}"
|
|
}
|
|
|
|
step_2_info() { echo "Create venv and install $toolName"; }
|
|
step_2() {
|
|
local macommanderDir="${MACO_DIR}"
|
|
|
|
exe python3 -m venv "$toolVenvDir"
|
|
endReturn -o $? "Creating virtual environment failed"
|
|
|
|
exe git clone $toolCloneUrl "$MACO_DIR"
|
|
exe chown -R $MACO_USER: "$toolVenvDir"
|
|
exe sudo -u $MACO_USER ${toolVenvDir}/bin/pip install --upgrade pip
|
|
}
|
|
|
|
step_3_info() { echo "Install python requirements"; }
|
|
step_3() {
|
|
cat <<NOTES_END
|
|
# Remove following packages for headless servers
|
|
|
|
dbus-python
|
|
notify2
|
|
NOTES_END
|
|
exe read -p "Enter to continue..."
|
|
exe "$DEFAULT_EDITOR_SYSTEM" "$MACO_DIR/requirements.txt"
|
|
exe sudo -u $MACO_USER ${toolVenvDir}/bin/pip install -r ${MACO_DIR}/requirements.txt
|
|
}
|
|
|
|
|
|
step_4_info() { echo "Create systemd service for $toolName"; }
|
|
step_4() {
|
|
local macommanderServiceLoc="/etc/systemd/system/matrix-commander.service"
|
|
local lService=$(eval "echo \"$macommanderService\"")
|
|
addConf -s "$lService" "$macommanderServiceLoc"
|
|
exe systemctl daemon-reload
|
|
}
|
|
macommanderService="[Unit]
|
|
Description=Matrix-Commander
|
|
After=syslog.target network-online.target
|
|
StartLimitIntervalSec=0
|
|
|
|
[Service]
|
|
User=\$MACO_USER
|
|
Group=\$MACO_USER
|
|
|
|
Type=simple
|
|
|
|
ExecStart=\${toolVenvDir}/bin/python3 \${MACO_DIR}/matrix-commander.py
|
|
TimeoutStopSec=20
|
|
#KillMode=process
|
|
Restart=always
|
|
RestartSec=5
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
Alias=matrix-commander.service"
|
|
|
|
VERSION_SEQREV=15
|
|
. /usr/local/bin/sequencer.sh
|