-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
89 lines (79 loc) · 2.67 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# TTControl
# Copyright (C) 2024 Steffen Schultz
# This work has been released under the terms of the MIT license
# See the file LICENSE for more details
set -e
# Script configuration
prefix="/usr/local/bin"
config_dir="/etc"
tt_user="teamtalk"
server_dir="/var/lib/teamtalk"
echo "Starting installation process.."
# Confirmation function
confirm() {
while true; do
read -rp "$1 [y/n]: " yn
case $yn in
[Yy]*) return 0 ;;
[Nn]*) return 1 ;;
*) echo "Please answer y for yes or n for no." ;;
esac
done
}
# Preparing ttcontrol script
if [ ! -x ttcontrol ]; then
chmod +x ttcontrol
fi
# Copy ttcontrol to desired location
echo "Checking for existing ttcontrol script..."
if [ -f "$prefix/ttcontrol" ]; then
echo "A version of ttcontrol is already installed at $prefix/ttcontrol."
if confirm "Do you want to overwrite it?"; then
echo "Creating backup..."
cp "$prefix/ttcontrol" "$prefix/ttcontrol.bak"
echo "Replacing ttcontrol with new version..."
install -m 0755 ttcontrol "$prefix/ttcontrol"
else
echo "Skipping installation step."
fi
else
echo "Installing ttcontrol to $prefix"
install -m 0755 ttcontrol "$prefix/ttcontrol"
fi
# Install config file
echo "Checking for existing configuration file..."
if [ -f "$config_dir/ttcontrol.conf" ]; then
echo "A configuration file already exists at $config_dir/ttcontrol.conf."
if confirm "Do you want to overwrite it?"; then
echo "Creating backup..."
cp "$config_dir/ttcontrol.conf" "$config_dir/ttcontrol.bak"
echo "Replacing ttcontrol.conf with new version..."
install -m 0644 ttcontrol.conf "$config_dir/ttcontrol.conf"
else
echo "Skipping installation step."
fi
else
echo "Creating configuration file at $config_dir"
install -m 0644 ttcontrol.conf "$config_dir/ttcontrol.conf"
fi
# Create a system user for teamtalk
echo "Checking for system user $tt_user..."
if id -u "$tt_user" >/dev/null 2>&1; then
echo "User $tt_user already exists, skipping step."
else
echo "Creating system user $tt_user"
useradd -r -s /bin/false "$tt_user"
echo "User $tt_user created successfully."
fi
# Create server directory if applicable
echo "Checking for server directory..."
if [ -d "$server_dir" ]; then
echo "Data directory $server_dir already exists, skipping step."
else
echo "Creating server directory at $server_dir"
mkdir -p "$server_dir/servers"
chown -R "$tt_user:$tt_user" "$server_dir"
echo "Server directory created and ownership set."
fi
echo "Installation process completed successfully. Enter ttcontrol to see all available options."