Files
shell_sequencer/seqs/matterbridge.sh

159 lines
4.0 KiB
Bash
Executable File

#!/bin/bash
#
## Installation of chat bridge matterbridge
toolName="matterbridge"
repoName="42wim"
toolLatestUrl="https://api.github.com/repos/${repoName}/${toolName}/releases/latest"
toolVersion=$(curl --silent "$toolLatestUrl" | grep -Po '"tag_name": "v\K.*?(?=")')
toolDownload="https://github.com/${repoName}/${toolName}/releases/download/v${toolVersion}/${toolName}-${toolVersion}-linux-armv6"
toolDir="/usr/local/bin"
toolLoc="${toolDir}/${toolName}"
toolWdir="/opt/${toolName}"
toolConfig="${toolName}.toml"
toolConfigLoc="${toolWdir}/${toolConfig}"
toolService="[Unit]
Description=${toolName}
After=network.target matrix-synapse.service
[Service]
Type=simple
ExecStart=${toolLoc} -conf ${toolWdir}/matterbridge.toml
Restart=always
RestartSec=30
WorkingDirectory=${toolWdir}
User=root
Group=root
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=${toolName}
[Install]
WantedBy=multi-user.target"
toolServiceLoc="/etc/systemd/system/${toolName}.service"
step_config() {
if [ -z $toolVersion ] ; then
echoerr " [E] Couldn't determine latest version of $toolName"
fi
}
step_1_info() {
echo "Downloading $toolName version ${toolVersion} to ${toolLoc} from:"
echoinfo "$toolDownload"
}
step_1_alias() { ALIAS="install"; }
step_1() {
step upgrade
endReturn -o $? "Download failed"
}
step_2_info() { echo "Create required directory structure"; }
step_2() {
exe mkdir -p ${toolWdir}
exe touch ${toolConfigLoc}
exe chmod -R 700 ${toolWdir}
exe chmod +x ${toolLoc}
}
step_3_info() { echo "Creating systemd service"; }
step_3() {
addConf -s "$toolService" "$toolServiceLoc"
endReturn -o $? "Creating service failed"
}
step_4_info() { echo "Enable $toolName service"; }
step_4() {
exe systemctl enable ${toolName}
echo " [I] Before proceeding to run ${toolName} you need to modify ${toolConfigLoc} first"
echo
}
step_5_info() { echo "Show configuration notes"; }
step_5_alias() { ALIAS="notes"; }
step_5() {
outColor green
cat <<NOTES_END
# Sample configuration
https://raw.githubusercontent.com/${repoName}/${toolName}/v${toolVersion}/matterbridge.toml.simple"
NOTES_END
}
step_12_info() {
if [ ! -z $versionNow ] ; then
if [ "$toolVersion" == "$versionNow" ] ; then
echo "No upgrade available. Already on latest: $versionNow"
else
echo "Download new version $toolVersion to /usr/local/bin"
echoinfo " - installed version: $versionNow -"
fi
else
echo "Download new version $toolVersion to /usr/local/bin"
fi
echo
}
step_12_alias() { ALIAS="upgrade"; }
step_12() {
if [ -f "$toolLoc" ] ; then
local toolBackup=
if [ ! -z ${versionNow} ] ; then
toolBackup="${toolDir}/${toolName}_${versionNow}"
else
toolBackup="${toolDir}/${toolName}_bu"
fi
exe service ${toolName} stop >>/dev/null 2>&1
echo -n " [I] Backing up existing executable to ${toolBackup}..."
exe cp -ar "$toolLoc" "$toolBackup" && echo "ok"
fi
exe wget -O "$toolLoc" $toolDownload
endReturn -o $? "Download failed"
exe chmod +x "$toolLoc"
exe service ${toolName} restart >>/dev/null 2>&1
return 0
}
versionNow=$([ ! -z $(which ${toolName}) ] && ${toolName} --version | sed 's/.*version: \([0-9.]\+\).*/\1/')
step_30_info() { echo "(TODO) Build from source"; }
step_30_alias() { ALIAS="build"; }
step_30() {
local goVer="$(curl --silent -L https://go.dev/doc/devel/release | \
grep --max-count 1 -E "go[[:digit:]\.]{3,}" |\
sed 's/.*go\([[:digit:]\.]\+\).*/\1/g')"
local goArch="armv6l" #arm64"
local goDownUrl="https://go.dev/dl/go${goVer}.linux-${goArch}.tar.gz"
local mabrTags="\
noapi,\
nodiscord,\
nogitter,\
noharmony,\
noirc,\
nokeybase,\
nomattermost,\
nomsteams,\
norocketchat,\
nonctalk,\
nomumble,\
noslack,\
nosshchat,\
notelegram,\
notwitch,\
novk,\
nozulip,\
whatsappmulti"
echoseq "Download go${goVer}: ${goDownUrl}"
echoseq "go install -tags ${mabrTags} github.com/42wim/matterbridge@master"
echoseq "step backup"
echoseq "cp -ar ${HOME}/go/bin/matterbridge /usr/local/bin"
}
# Sequence Revision
VERSION_SEQREV=15
# Path to sequencer
. /usr/local/bin/sequencer.sh