#!/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" readonly goDir="/usr/local/go" readonly goDownLoc="/tmp/go.tar.gz" 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 <>/dev/null 2>&1 echoseq -n " [I] Backing up existing executable to ${toolBackup}..." exe cp -ar "$toolLoc" "$toolBackup" && echoseq "ok" fi } versionNow=$([ ! -z $(which ${toolName}) ] && ${toolName} --version | sed 's/.*version: \([0-9.]\+\).*/\1/') 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 $toolDir" echoinfo " - installed version: $versionNow -" fi else echo "Download new version $toolVersion to $toolDir" fi echo } step_12_alias() { ALIAS="upgrade"; } step_12() { step backup exe wget -O "$toolLoc" $toolDownload endReturn -o $? "Download failed" exe chmod +x "$toolLoc" exe service ${toolName} restart >>/dev/null 2>&1 return 0 } step_30_info() { echo "Download go"; } 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" # Download latest go if [ ! -e "${goDir}" ] ; then echoseq "Download go${goVer}: ${goDownUrl}" exe wget -O "${goDownLoc}" ${goDownUrl} endReturn -o $? "Download ${goVer} failed" exe tar -C "$(dirname -- "${goDir}")" -xzf "${goDownLoc}" endReturn -o $? "Extraction ${goVer} failed" fi } step_31_info() { echo "Compile matterbridge"; } step_31() { local mabrTags="\ noapi,\ nodiscord,\ nogitter,\ noharmony,\ noirc,\ nokeybase,\ nomattermost,\ nomsteams,\ norocketchat,\ nonctalk,\ nomumble,\ noslack,\ nosshchat,\ notelegram,\ notwitch,\ novk,\ nozulip,\ whatsappmulti" # Compile matterbridge exe "${goDir}/bin/go" install -tags ${mabrTags} github.com/42wim/matterbridge@master step backup exe cp -ar "${HOME}/go/bin/matterbridge" "${toolDir}" } step_32_info() { echo "Clean temporary files"; } step_32() { exe rm -f "${goDownLoc}" } # Sequence Revision VERSION_SEQREV=15 # Path to sequencer . /usr/local/bin/sequencer.sh