Merge branch '__matterbridge' into 'master'
__matterbridge type See merge request ungleich-public/cdist-contrib!3
This commit is contained in:
commit
10ccc77803
5 changed files with 174 additions and 0 deletions
18
type/__matterbridge/files/matterbridge.service.sh
Executable file
18
type/__matterbridge/files/matterbridge.service.sh
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/sh
|
||||
|
||||
cat <<EOF
|
||||
[Unit]
|
||||
Description=IM bridging daemon
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
User=$USER
|
||||
Group=$GROUP
|
||||
Type=simple
|
||||
Restart=on-failure
|
||||
ExecStart=$BINARY_PATH -conf=/etc/matterbridge/matterbridge.toml
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
56
type/__matterbridge/man.rst
Normal file
56
type/__matterbridge/man.rst
Normal file
|
@ -0,0 +1,56 @@
|
|||
cdist-type__matterbridge(7)
|
||||
===========================
|
||||
|
||||
NAME
|
||||
----
|
||||
cdist-type__matterbridge - Install matterbridge from upstream binary
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
This singleton type install a matterbridge service from binary.
|
||||
|
||||
REQUIRED PARAMETERS
|
||||
-------------------
|
||||
version
|
||||
Release (git tag) to fetch from the project github's page.
|
||||
|
||||
config
|
||||
Matterbridge configuration (TOML).
|
||||
|
||||
OPTIONAL PARAMETERS
|
||||
-------------------
|
||||
None.
|
||||
|
||||
|
||||
BOOLEAN PARAMETERS
|
||||
------------------
|
||||
None.
|
||||
|
||||
|
||||
EXAMPLES
|
||||
--------
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
__matterbridge --version 1.16.3 --config - << EOF
|
||||
[...]
|
||||
EOF
|
||||
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
- `Matterbridge github repository <https://github.com/42wim/matterbridge>`_
|
||||
|
||||
|
||||
AUTHORS
|
||||
-------
|
||||
Timothée Floure <timothee.floure@ungleich.ch>
|
||||
|
||||
|
||||
COPYING
|
||||
-------
|
||||
Copyright \(C) 2020 Timothée Floure. You can redistribute it
|
||||
and/or modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
98
type/__matterbridge/manifest
Executable file
98
type/__matterbridge/manifest
Executable file
|
@ -0,0 +1,98 @@
|
|||
#!/bin/sh -e
|
||||
#
|
||||
# 2020 Timothée Floure (timothee.floure@ungleich.ch)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
# cdist is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# cdist is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
os=$(cat "$__global/explorer/os")
|
||||
case "$os" in
|
||||
debian)
|
||||
# This type assume systemd for service installation.
|
||||
;;
|
||||
*)
|
||||
printf "Your operating system (%s) is currently not supported by this type (%s)\n" "$os" "${__type##*/}" >&2
|
||||
printf "Please contribute an implementation for it if you can.\n" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Required parameters.
|
||||
VERSION=$(cat "$__object/parameter/version")
|
||||
if [ -f "$__object/parameter/config" ]; then
|
||||
CONFIG="$(cat "$__object/parameter/config")"
|
||||
if [ "$CONFIG" = "-" ]; then
|
||||
CONFIG=$(cat "$__object/stdin")
|
||||
fi
|
||||
fi
|
||||
|
||||
# Hardcoded values used in templates.
|
||||
export BINARY_PATH=/usr/local/bin/matterbridge
|
||||
export CONFIG_PATH=/etc/matterbridge/matterbridge.toml
|
||||
export USER=matterbridge
|
||||
export GROUP=$USER
|
||||
|
||||
# Internal variables.
|
||||
artefact="matterbridge-$VERSION-linux-64bit"
|
||||
checksum_file="checksums.txt"
|
||||
release_download_url=https://github.com/42wim/matterbridge/releases/download
|
||||
binary_url="$release_download_url/v$VERSION/$artefact"
|
||||
checksum_file_url="$release_download_url/v$VERSION/$checksum_file"
|
||||
config_dir=$(dirname $CONFIG_PATH)
|
||||
systemd_unit_path='/etc/systemd/system/matterbridge.service'
|
||||
|
||||
# Check if curl is available.
|
||||
if ! command -v curl; then
|
||||
echo "curl is required for this type, but could not be found. Exiting." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Initialize working directory.
|
||||
mkdir -p "$__object/files"
|
||||
|
||||
# Download and check matterbridge binary.
|
||||
curl -L "$binary_url" -o "$__object/files/$artefact"
|
||||
curl -Ls "$checksum_file_url" | grep "$artefact" > "$__object/files/$checksum_file"
|
||||
if ! (cd "$__object/files"; sha256sum --check $checksum_file); then
|
||||
echo "Matterbridge binary checksum failed." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create service user.
|
||||
__user $USER --home "/var/lib/$USER"
|
||||
|
||||
# Deploy matterbridge binary.
|
||||
require="__user/$USER" __file "$BINARY_PATH" \
|
||||
--source "$__object/files/$artefact" \
|
||||
--owner "$USER" --mode 755
|
||||
|
||||
# Generate and deploy configuration file.
|
||||
"$__type/files/matterbridge.service.sh" > "$__object/files/matterbridge.service"
|
||||
|
||||
require="__user/$USER" __directory "$config_dir" \
|
||||
--owner "$USER" --mode 0755 --parents \
|
||||
|
||||
require="__directory/$config_dir" __file "$CONFIG_PATH" \
|
||||
--owner "$USER" \
|
||||
--mode 0640 \
|
||||
--source "$CONFIG"
|
||||
|
||||
__file "$systemd_unit_path" \
|
||||
--source "$__object/files/matterbridge.service"
|
||||
|
||||
# Deal with init system.
|
||||
require="__file/$systemd_unit_path" __start_on_boot matterbridge
|
||||
require="__file/$BINARY_PATH __file/$CONFIG_PATH __file/$systemd_unit_path" __service matterbridge --action restart
|
2
type/__matterbridge/parameter/required
Normal file
2
type/__matterbridge/parameter/required
Normal file
|
@ -0,0 +1,2 @@
|
|||
version
|
||||
config
|
0
type/__matterbridge/singleton
Normal file
0
type/__matterbridge/singleton
Normal file
Loading…
Reference in a new issue