Added support for FreeBSD
Bryan Roe committed
Jul 22, 2019 at 17:23 UTC
2e8446fc902a8bb45a2bd1f763d19455afa57e31
3 files changed
+73
-16
agents/meshagent_freebsd64
Binary files /dev/null and b/agents/meshagent_freebsd64 differ
agents/meshinstall-bsd-rcd.sh
new
+17
@@ -0,0 +1,17 @@
1
+#!/bin/sh
2
+# PROVIDE: meshagent
3
+# REQUIRE: FILESYSTEMS NETWORKING
4
+# KEYWORD: shutdown
5
+. /etc/rc.subr
6
+
7
+name="meshagent"
8
+desc="MeshCentral Agent"
9
+rcvar=${name}_enable
10
+pidfile="/var/run/meshagent.pid"
11
+command="/usr/sbin/daemon"
12
+command_args="-P ${pidfile} -r -f /usr/local/mesh/meshagent "
13
+command_chdir="/usr/local/mesh"
14
+
15
+load_rc_config $name
16
+: ${meshagent_enable="YES"}
17
+run_rc_command "$1"
\ No newline at end of file
agents/meshinstall-linux.sh
+56
-16
@@ -1,18 +1,31 @@
1
-#!/bin/bash
1
+#!/usr/bin/env bash
2
3
CheckStartupType() {
4
+ # 1 = Systemd
5
+ # 2 = Upstart
6
+ # 3 = init.d
7
+ # 5 = BSD
8
+
9
+ # echo "Checking if Linux or BSD Platform"
10
+ plattype=`uname | awk '{ tst=tolower($0);a=split(tst, res, "bsd"); if(a==1) { print "LINUX"; } else { print "BSD"; }}'`
11
+ if [[ $plattype == 'BSD' ]]
12
+ then return 5;
13
+ fi
14
+
15
# echo "Checking process autostart system..."
5
- starttype=`ps -p 1 | awk '/1/ {print $4}'`
16
+ starttype=`ps -p 1 -o command= | awk '{ a=split($0, res, "/"); split(res[a], f, " "); print f[1]}'`
17
+
18
# Systemd
7
- if [[ $starttype == 'systemd' ]]; then return 1;
8
- elif [[ $starttype == 'init' ]];
9
- then
10
- # Upstart
11
- /sbin/init --version && [[ `/sbin/init --version` =~ upstart ]] && return 2 || return 3
12
- # if [[ `/sbin/init --version` =~ upstart ]]; then return 2;
13
- # Sysv-init
14
- # return 3;
15
- # fi
19
+ if [[ $starttype == 'systemd' ]]
20
+ then return 1;
21
+ elif [[ $starttype == 'init' ]]
22
+ then
23
+ if [ -d "/etc/init" ]
24
+ then
25
+ return 2;
26
+ else
27
+ return 3;
28
+ fi
29
fi
30
return 0;
31
}
@@ -55,13 +68,25 @@ CheckInstallAgent() {
68
# echo "Detecting computer type..."
69
if [ $machinetype == 'x86_64' ] || [ $machinetype == 'amd64' ]
70
then
58
- # Linux x86, 64 bit
59
- machineid=6
71
+ if [ $starttype -eq 5 ]
72
+ then
73
+ # FreeBSD x86, 64 bit
74
+ machineid=30
75
+ else
76
+ # Linux x86, 64 bit
77
+ machineid=6
78
+ fi
79
fi
80
if [ $machinetype == 'x86' ] || [ $machinetype == 'i686' ] || [ $machinetype == 'i586' ]
81
then
63
- # Linux x86, 32 bit
64
- machineid=5
82
+ if [ $starttype -eq 5 ]
83
+ then
84
+ # FreeBSD x86, 32 bit
85
+ machineid=31
86
+ else
87
+ # Linux x86, 32 bit
88
+ machineid=5
89
+ fi
90
fi
91
if [ $machinetype == 'armv6l' ] || [ $machinetype == 'armv7l' ]
92
then
@@ -164,6 +189,15 @@ DownloadAgent() {
189
echo 'meshagent installed as upstart/init.d service.'
190
echo 'To start service: sudo initctl start meshagent'
191
echo 'To stop service: sudo initctl stop meshagent'
192
+ elif [ $starttype -eq 5 ]
193
+ then
194
+ # FreeBSD
195
+ wget $url/meshagents?script=5 {{{wgetoptionshttps}}}-O /usr/local/etc/rc.d/meshagent || curl {{{curloptionshttps}}}--output /usr/local/etc/rc.d/meshagent $url/meshagents?script=5
196
+ chmod +x /usr/local/etc/rc.d/meshagent
197
+ service meshagent start
198
+ echo 'meshagent installed as BSD service.'
199
+ echo 'To start service: sudo service meshagent start'
200
+ echo 'To stop service: sudo service meshagent stop'
201
else
202
# unknown
203
echo "Unknown Service Platform Type. (ie: init, systemd, etc)"
@@ -211,7 +245,13 @@ UninstallAgent() {
245
rm -f /etc/rc2.d/S20mesh /etc/rc3.d/S20mesh /etc/rc5.d/S20mesh
246
initctl stop meshagentDiagnostic &> /dev/null
247
rm -f /etc/init/meshagentDiagnostic.conf &> /dev/null
214
- fi
248
+ elif [ $starttype -eq 5 ]; then
249
+ # FreeBSD
250
+ service meshagent stop
251
+ service meshagentDiagnostic stop &> /dev/null
252
+ rm -f /usr/local/etc/rc.d/meshagent
253
+ rm -f /usr/local/etc/rc.d/meshagentDiagnostic &> /dev/null
254
+ fi
255
fi
256
257
if [ -e $installpath ]