#!/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" seq_config() { if [ -z "${toolVersion}" ] ; then error -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() { echo "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() { echo "notes"; } step_5() { color green cat <>/dev/null 2>&1' info -n "Backing up existing executable to ${toolBackup}..." exe cp -ar "$toolLoc" "$toolBackup" && info -d "ok" fi } versionNow=$([ -n "$(command -v ${toolName})" ] && ${toolName} --version | sed 's/.*version: \([0-9.]\+\).*/\1/') step_12_info() { if [ -n "${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() { echo "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" echoinfo " [OPTIONS]" echoinfo " --arch, -a : armhf(default), arm64" echoinfo " CPU architecture for downloading go sources" } step_30_options() { echo "[OPTIONS]"; } step_30_alias() { echo "build"; } step_30() { shift local goVer goVer="$(curl --silent -L https://go.dev/dl | \ grep --max-count 1 -E "go[[:digit:]\.]{3,}.*\.tar\.gz" |\ sed 's/.*\/\(go.*\)\.linux.*/\1/g')" local goArch="armhf" #arm64" case "${1:-}" in --arch|-a) goArch="${2:-"armhf"}" shift 2 ;; esac [[ "${goArch}" == "armhf" ]] && goArch="armv6l" local goDownUrl="https://go.dev/dl/${goVer}.linux-${goArch}.tar.gz" # Download latest go if [ ! -e "${goDir}" ] ; then info "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}" exep service ${toolName} restart '>>/dev/null 2>&1' } step_32_info() { echo "Clean temporary files"; } step_32() { exe rm -f "${goDownLoc}" } # Sequence Revision readonly sqr_minVersion=16 # Path to sequencer . /usr/local/bin/sequencer.sh