205 lines
5.3 KiB
Bash
Executable File
205 lines
5.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
#
|
|
## Installation of chat bridge matterbridge
|
|
|
|
readonly toolName="matterbridge"
|
|
readonly repoName="42wim"
|
|
readonly toolLatestUrl="https://api.github.com/repos/${repoName}/${toolName}/releases/latest"
|
|
readonly toolVersion=$(curl --silent "$toolLatestUrl" | grep -Po '"tag_name": "v\K.*?(?=")')
|
|
readonly toolDownload="https://github.com/${repoName}/${toolName}/releases/download/v${toolVersion}/${toolName}-${toolVersion}-linux-armv6"
|
|
readonly toolDir="/usr/local/bin"
|
|
readonly toolLoc="${toolDir}/${toolName}"
|
|
readonly toolWdir="/etc/${toolName}"
|
|
readonly toolConfig="${toolName}.toml"
|
|
readonly toolConfigLoc="${toolWdir}/${toolConfig}"
|
|
readonly toolUser='matterbridge'
|
|
readonly toolService="[Unit]
|
|
Description=${toolName}
|
|
After=network-online.target matrix-synapse.service
|
|
|
|
[Service]
|
|
Type=simple
|
|
ExecStart=${toolLoc} -conf ${toolWdir}/matterbridge.toml
|
|
Restart=always
|
|
RestartSec=5s
|
|
WorkingDirectory=${toolWdir}
|
|
User=${toolUser}
|
|
|
|
[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 "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 system user ${toolUser}"; }
|
|
step_3() {
|
|
exe adduser --system --group --home "${toolWdir}" "${toolUser}"
|
|
}
|
|
|
|
step_4_info() { echo "Creating systemd service"; }
|
|
step_4() {
|
|
addConf -s "$toolService" "$toolServiceLoc"
|
|
endReturn "Creating service failed"
|
|
}
|
|
|
|
step_5_info() { echo "Enable $toolName service"; }
|
|
step_5() {
|
|
exe systemctl enable ${toolName}
|
|
info "Before proceeding to run ${toolName} you need to modify ${toolConfigLoc} first"
|
|
echo
|
|
}
|
|
|
|
step_6_info() { echo "Show configuration notes"; }
|
|
step_6_alias() { echo "notes"; }
|
|
step_6() {
|
|
color green
|
|
cat <<NOTES_END
|
|
|
|
# Sample configuration
|
|
|
|
https://raw.githubusercontent.com/${repoName}/${toolName}/v${toolVersion}/matterbridge.toml.simple"
|
|
|
|
NOTES_END
|
|
}
|
|
|
|
step_10_info() { echo "Backup existing executable"; }
|
|
step_10_alias() { echo "backup"; }
|
|
step_10() {
|
|
if [ -f "$toolLoc" ] ; then
|
|
local toolBackup=
|
|
if [ -n "${versionNow}" ] ; then
|
|
toolBackup="${toolDir}/${toolName}_${versionNow}"
|
|
else
|
|
toolBackup="${toolDir}/${toolName}_bu"
|
|
fi
|
|
exep service ${toolName} stop '>>/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 "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 "Download ${goVer} failed"
|
|
exe tar -C "$(dirname -- "${goDir}")" -xzf "${goDownLoc}"
|
|
endReturn "Extraction ${goVer} failed"
|
|
fi
|
|
}
|
|
|
|
step_31_info() { echo "Compile matterbridge"; }
|
|
step_31_alias() { echo 'compile'; }
|
|
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_alias() { echo "clean"; }
|
|
step_32() {
|
|
exe rm -f "${goDownLoc}"
|
|
}
|
|
|
|
# shellcheck disable=SC2034 # Appears unused
|
|
readonly sqr_minVersion=16
|
|
# shellcheck disable=SC1091 # Don't follow this source
|
|
. /usr/local/bin/sequencer.sh
|