forked from milos85vasic/Server-Factory-Utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_mdns_remote.sh
More file actions
executable file
·119 lines (86 loc) · 2.23 KB
/
init_mdns_remote.sh
File metadata and controls
executable file
·119 lines (86 loc) · 2.23 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh
name=$2
machine=$1
if [ -z "$3" ]; then
port="22"
else
port=$2
fi
echo "$machine: Checking reachability"
if ping -c 3 "$machine" >/dev/null 2>&1; then
echo "$machine: Reachable"
else
echo "ERROR: $machine is unreachable"
exit 1
fi
no_manager="none"
install="$no_manager"
if ssh -p "$port" root@"$machine" "which dnf"; then
if ssh -p "$port" root@"$machine" "cat /etc/os-release | grep -i centos" >/dev/null 2>&1; then
if ssh -p "$port" root@"$machine" "dnf install -y epel-release"; then
echo "EPEL installed"
else
echo "Could not install EPEL"
exit 1
fi
else
packages="avahi-tools"
fi
install="dnf install -y"
packages="nss-mdns avahi $packages"
else
if ssh -p "$port" root@"$machine" "which yum"; then
install="yum install -y"
packages="nss-mdns avahi avahi-tools"
else
if ssh -p "$port" root@"$machine" "which apt"; then
install="apt install -y"
packages="avahi-daemon avahi-discover avahi-utils libnss-mdns mdns-scan"
else
if ssh -p "$port" root@"$machine" "which pacman"; then
# TODO: Support for Arch and Manjaro
install="pacman -Syu"
packages="nss-mdns avahi avahi-tools"
fi
fi
fi
fi
if [ "$install" = "$no_manager" ]; then
echo "ERROR: No package manager recognized"
exit 1
fi
if ssh -p "$port" root@"$machine" "$install $packages"; then
echo "$packages: Installed"
else
echo "ERROR: $packages not installed"
exit 1
fi
service="avahi-daemon.service"
enable_service="systemctl enable --now $service"
if ssh -p "$port" root@"$machine" "$enable_service"; then
echo "$service: Enabled"
else
echo "ERROR: $service not enabled"
exit 1
fi
if ssh -p "$port" root@"$machine" "hostnamectl set-hostname $name"; then
echo "$name: Set to $machine"
else
echo "ERROR: $name not set to $machine"
exit 1
fi
restart_service="systemctl restart $service"
if ssh -p "$port" root@"$machine" "$restart_service"; then
echo "$service: Restarted"
else
echo "ERROR: $service not restarted"
exit 1
fi
echo "$name: Checking reachability"
if ping -c 3 "$name" >/dev/null 2>&1; then
echo "$name: Reachable"
else
echo "ERROR: $name is unreachable"
exit 1
fi
echo "mDNS setup completed with success"