Skip to content

Commit ae9b59c

Browse files
hatateayaTjzabel
andauthored
Add an installation script to install as a systemd unit (#443)
Co-authored-by: Tim Zabel <Tjzabel21@gmail.com>
1 parent 602c7ee commit ae9b59c

File tree

2 files changed

+173
-1
lines changed

2 files changed

+173
-1
lines changed

deployments/systemd/install.sh

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/bin/bash
2+
3+
set -e -o pipefail
4+
5+
print_sep() {
6+
local cols line
7+
cols=${COLUMNS:-$(tput cols 2>/dev/null || echo 80)}
8+
printf -v line '%*s' "$cols" ''
9+
printf '%s\n' "${line// /-}"
10+
}
11+
12+
echo "Starting TeleIRC installation script..."
13+
print_sep
14+
15+
echo "Checking if systemd is the init system..."
16+
check_systemd_is_init() {
17+
if [ "$(basename "$(readlink /proc/1/exe)")" = "systemd" ]; then
18+
return 0
19+
else
20+
return 1
21+
fi
22+
}
23+
if ! check_systemd_is_init; then
24+
echo "Error: This script requires systemd as the init system." >&2
25+
exit 1
26+
else
27+
echo "systemd is the init system. Continuing..."
28+
fi
29+
print_sep
30+
31+
echo "Checking if sudo and curl is installed..."
32+
if ! command -v sudo &> /dev/null; then
33+
echo "sudo could not be found. Please install sudo and re-run this script." >&2
34+
exit 1
35+
else
36+
echo "sudo is installed. Continuing..."
37+
fi
38+
if ! command -v curl &> /dev/null; then
39+
echo "curl could not be found. Please install curl and re-run this script." >&2
40+
exit 1
41+
else
42+
echo "curl is installed. Continuing..."
43+
fi
44+
print_sep
45+
46+
echo "Fetching the latest TeleIRC version tag from Anitya API..."
47+
ANITYA_API_URL="https://release-monitoring.org/api/v2/versions/?project_id=386778"
48+
LATEST_VERSION=$(curl -sL "$ANITYA_API_URL" | sed -n 's/.*"latest_version":"\([^"]*\)".*/\1/p')
49+
if [[ -z "$LATEST_VERSION" ]]; then
50+
echo "Error: Could not retrieve or parse the latest version tag of TeleIRC from Anitya API." >&2
51+
exit 1
52+
fi
53+
VER=$LATEST_VERSION
54+
echo "Selecting TeleIRC version ${VER}..."
55+
print_sep
56+
57+
echo "Creating temporary working directory..."
58+
TMP_DIR=$(mktemp -d)
59+
if [ ! -d "$TMP_DIR" ]; then
60+
echo "Error: Failed to create temporary directory." >&2
61+
exit 1
62+
else
63+
echo "Temporary directory created at ${TMP_DIR}."
64+
fi
65+
print_sep
66+
67+
cleanup() {
68+
if [ -n "${TMP_DIR:-}" ] && [ -d "$TMP_DIR" ]; then
69+
echo "Cleaning up temporary files from ${TMP_DIR} ..."
70+
rm -rvf "$TMP_DIR"
71+
fi
72+
}
73+
trap cleanup EXIT INT
74+
75+
GITHUB_RELEASE_URL="https://github.com/RITlug/teleirc/releases/download/v${VER}"
76+
GITHUB_RAW_URL="https://raw.githubusercontent.com/RITlug/teleirc/v${VER}"
77+
echo "Set GITHUB_RELEASE_URL to ${GITHUB_RELEASE_URL}"
78+
echo "Set GITHUB_RAW_URL to ${GITHUB_RAW_URL}"
79+
print_sep
80+
81+
echo "Downloading TeleIRC deployment assets from GitHub..."
82+
curl --verbose --location --output "${TMP_DIR}"/teleirc "${GITHUB_RELEASE_URL}"/teleirc-${VER}-linux-x86_64
83+
curl --verbose --location --output "${TMP_DIR}"/teleirc.sysusers "${GITHUB_RAW_URL}"/deployments/systemd/teleirc.sysusers
84+
curl --verbose --location --output "${TMP_DIR}"/teleirc.tmpfiles "${GITHUB_RAW_URL}"/deployments/systemd/teleirc.tmpfiles
85+
curl --verbose --location --output "${TMP_DIR}"/teleirc@.service "${GITHUB_RAW_URL}"/deployments/systemd/teleirc@.service
86+
curl --verbose --location --output "${TMP_DIR}"/teleirc.env "${GITHUB_RAW_URL}"/env.example
87+
print_sep
88+
89+
if [ -z "$EDITOR" ]; then
90+
if command -v vim &> /dev/null; then
91+
EDITOR="vim"
92+
else
93+
EDITOR="nano"
94+
fi
95+
fi
96+
echo "Selected EDITOR as ${EDITOR} ..."
97+
print_sep
98+
99+
echo "Please edit the TeleIRC environment file to configure your bridge settings..."
100+
$EDITOR "${TMP_DIR}"/teleirc.env
101+
print_sep
102+
103+
echo "Please make sure you configured TeleIRC correctly in ${TMP_DIR}/teleirc.env before proceeding!"
104+
echo "Press any key to continue..."
105+
read -n 1 -s -r
106+
print_sep
107+
108+
echo "Installing TeleIRC files and user..."
109+
sudo install -v -Dm755 -o root -g root "${TMP_DIR}"/teleirc /usr/local/bin/teleirc
110+
sudo install -v -Dm644 -o root -g root "${TMP_DIR}"/teleirc.sysusers /etc/sysusers.d/teleirc.conf
111+
sudo install -v -Dm644 -o root -g root "${TMP_DIR}"/teleirc.tmpfiles /etc/tmpfiles.d/teleirc.conf
112+
sudo install -v -Dm644 -o root -g root "${TMP_DIR}"/teleirc@.service /etc/systemd/system/teleirc@.service
113+
sudo systemd-sysusers /etc/sysusers.d/teleirc.conf
114+
sudo systemd-tmpfiles --create /etc/tmpfiles.d/teleirc.conf
115+
sudo install -v -Dm644 -o root -g root "${TMP_DIR}"/teleirc.env /etc/teleirc/bridge
116+
print_sep
117+
118+
echo "Checking if SELinux is installed and enforced..."
119+
check_selinux_status() {
120+
if ! command -v getenforce &> /dev/null; then
121+
return 1
122+
fi
123+
SELINUX_STATUS=$(getenforce)
124+
case "$SELINUX_STATUS" in
125+
"Enforcing")
126+
return 0
127+
;;
128+
*)
129+
return 1
130+
;;
131+
esac
132+
}
133+
if check_selinux_status; then
134+
echo "SELinux is enforced. Setting SELinux context for TeleIRC files..."
135+
sudo chcon --type bin_t --user system_u /usr/local/bin/teleirc
136+
sudo chcon --type etc_t --user system_u -R /etc/teleirc/
137+
sudo chcon --type etc_t --user system_u /etc/sysusers.d/teleirc.conf
138+
sudo chcon --type etc_t --user system_u /etc/tmpfiles.d/teleirc.conf
139+
sudo chcon --type systemd_unit_file_t --user system_u /etc/systemd/system/teleirc@.service
140+
else
141+
echo "SELinux is not enforcing or not installed. We have no need to set it up."
142+
fi
143+
print_sep
144+
145+
echo "Enabling TeleIRC systemd service unit..."
146+
sudo systemctl enable teleirc@bridge.service
147+
echo "Enabled TeleIRC systemd service unit."
148+
print_sep
149+
150+
read -p "Do you want to start TeleIRC now? (y/n): " response
151+
if [[ "$response" =~ ^[Yy]$ ]]; then
152+
echo "Starting TeleIRC..."
153+
sudo systemctl start teleirc@bridge.service
154+
else
155+
echo "Skipping starting TeleIRC..."
156+
fi
157+
print_sep
158+
159+
echo "Installation of TeleIRC version ${VER} is completed."

docs/user/quick-start.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,19 @@ To start the bot, you need to consider the following factors:
196196
_Looking for an easier way?_
197197
_Check out the [TeleIRC Ansible Role][17] for an automated installation of the following steps._
198198

199-
Upstream offers a [systemd unit file][15] to automate TeleIRC on a Linux system that uses [systemd][16].
199+
**NOTE**:
200+
You can also try an one-line installation using an [installation script][18] upstream offers. Just:
201+
202+
`curl -fsSL https://raw.githubusercontent.com/RITlug/teleirc/refs/heads/main/deployments/systemd/install.sh | sh`
203+
204+
This script will install an [systemd unit file][15] upstream offers to automatic TeleIRC on your Linux system;
205+
Let you to use an terminal editor to configure your TeleIRC;
206+
Then enable it that it will automate start with your system and start it immediately if you choose to do so.
207+
208+
Notice: Using this installation script, You need check your system is using [systemd][16] as init and bash, sudo, curl are installed and nano or vim is installed.
209+
Also you'd better prepared the parameters needed to be set in TeleIRC's configuration.
210+
211+
Upstream offers a systemd unit file to automate TeleIRC on a Linux system that uses systemd.
200212
This example uses the upstream systemd unit file to automatically run TeleIRC on a Linux system.
201213

202214
This example was tested on a CentOS 8 system and is easily adaptable for other `*NIX` distributions.
@@ -252,3 +264,4 @@ service named teleirc@FILENAME.service.
252264
[15]: https://github.com/RITlug/teleirc/blob/master/deployments/systemd/teleirc@.service
253265
[16]: https://systemd.io/
254266
[17]: https://github.com/jwflory/ansible-role-teleirc
267+
[18]: https://github.com/RITlug/teleirc/blob/main/deployments/systemd/install.sh

0 commit comments

Comments
 (0)