more Linux install script fixes.

Ylian Saint-Hilaire committed Mar 1, 2019 at 18:07 UTC 384fb47f458024f778630106189e04ee2e4cc14a
4 files changed +90 -91
agents/meshinstall-initd.sh
+35 -40
@@ -30,58 +30,53 @@ stop() {
30 echo 'Service not running' >&2
31 return 1
32 else
33 - pid=$( cat "$PIDFILE" )
34 - if kill -0 $pid 2>/dev/null; then
33 + pid=$( cat "$PIDFILE" )
34 + if kill -0 $pid 2>/dev/null; then
35 echo 'Stopping service…' >&2
36 kill -16 $pid
37 echo 'Service stopped' >&2
38 - else
39 - echo 'Service not running'
40 - fi
41 - rm -f $"PIDFILE"
38 + else
39 + echo 'Service not running'
40 + fi
41 + rm -f $"PIDFILE"
42 fi
43 }
44 restart(){
45 - stop
46 - start
45 + stop
46 + start
47 }
48 status(){
49 - if [ -f "$PIDFILE" ]
50 - then
51 - pid=$( cat "$PIDFILE" )
52 - if kill -0 $pid 2>/dev/null; then
53 - echo "meshagent start/running, process $pid"
54 - else
55 - echo 'meshagent stop/waiting'
56 - fi
57 - else
58 - echo 'meshagent stop/waiting'
59 - fi
49 + if [ -f "$PIDFILE" ]
50 + then
51 + pid=$( cat "$PIDFILE" )
52 + if kill -0 $pid 2>/dev/null; then
53 + echo "meshagent start/running, process $pid"
54 + else
55 + echo 'meshagent stop/waiting'
56 + fi
57 + else
58 + echo 'meshagent stop/waiting'
59 + fi
60
61 }
62
63
64 case "$1" in
65 - start)
66 - start
67 - ;;
68 - stop)
69 - stop
70 - ;;
71 - restart)
72 - stop
73 - start
74 - ;;
75 - status)
76 - status
77 - ;;
78 - *)
79 - echo "Usage: service meshagent {start|stop|restart|status}"
80 - ;;
65 + start)
66 + start
67 + ;;
68 + stop)
69 + stop
70 + ;;
71 + restart)
72 + stop
73 + start
74 + ;;
75 + status)
76 + status
77 + ;;
78 + *)
79 + echo "Usage: service meshagent {start|stop|restart|status}"
80 + ;;
81 esac
82 exit 0
83 -
84 -
85 -
86 -
87 -
agents/meshinstall-linux.sh
+49 -48
@@ -3,13 +3,13 @@
3 CheckStartupType() {
4 # echo "Checking process autostart system..."
5 starttype=`ps -p 1 | awk '/1/ {print $4}'`
6 - # 1 is Systemd;
6 + # Systemd
7 if [[ $starttype == 'systemd' ]]; then return 1;
8 elif [[ $starttype == 'init' ]];
9 then
10 - # 2 is Upstart
10 + # Upstart
11 if [[ `/sbin/init --version` =~ upstart ]]; then return 2;
12 - # 3 is Sysv-init
12 + # Sysv-init
13 return 3;
14 fi
15 fi
@@ -47,8 +47,8 @@ CheckInstallAgent() {
47 if [ $# -ge 3 ]
48 then
49 # echo "Computer type is specified..."
50 - machineid=$3
51 - else
50 + machineid=$3
51 + else
52 # echo "Detecting computer type..."
53 if [ $machinetype == 'x86_64' ] || [ $machinetype == 'amd64' ]
54 then
@@ -66,9 +66,9 @@ CheckInstallAgent() {
66 machineid=25
67 fi
68 # Add more machine types, detect KVM support... here.
69 - fi
69 + fi
70
71 - if [ $machineid -eq 0 ]
71 + if [ $machineid -eq 0 ]
72 then
73 echo "Unsupported machine type: $machinetype."
74 else
@@ -92,13 +92,13 @@ DownloadAgent() {
92 mkdir -p /usr/local/mesh
93 cd /usr/local/mesh
94 echo "Downloading Mesh agent #$machineid..."
95 - wget $url/meshagents?id=$machineid --no-check-certificate -O /usr/local/mesh/meshagent
95 + wget $url/meshagents?id=$machineid --no-check-certificate {{{noproxy}}}-O /usr/local/mesh/meshagent
96
97 # If it did not work, try again using http
98 if [ $? != 0 ]
99 then
100 url=${url/"https://"/"http://"}
101 - wget $url/meshagents?id=$machineid -O /usr/local/mesh/meshagent
101 + wget $url/meshagents?id=$machineid {{{noproxy}}}-O /usr/local/mesh/meshagent
102 fi
103
104 if [ $? -eq 0 ]
@@ -106,62 +106,62 @@ DownloadAgent() {
106 echo "Mesh agent downloaded."
107 # TODO: We could check the meshagent sha256 hash, but best to authenticate the server.
108 chmod 755 /usr/local/mesh/meshagent
109 - wget $url/meshsettings?id=$meshid --no-check-certificate -O /usr/local/mesh/meshagent.msh
109 + wget $url/meshsettings?id=$meshid --no-check-certificate {{{noproxy}}}-O /usr/local/mesh/meshagent.msh
110
111 # If it did not work, try again using http
112 if [ $? -ne 0 ]
113 then
114 - wget $url/meshsettings?id=$meshid -O /usr/local/mesh/meshagent.msh
114 + wget $url/meshsettings?id=$meshid {{{noproxy}}}-O /usr/local/mesh/meshagent.msh
115 fi
116
117 if [ $? -eq 0 ]
118 then
119 - UpdateMshFile
119 + UpdateMshFile
120 if [ $starttype -eq 1 ]
121 then
122 - # systemd
123 - if [ -d "/lib/systemd/system/" ]
124 - then
122 + # systemd
123 + if [ -d "/lib/systemd/system/" ]
124 + then
125 echo -e "[Unit]\nDescription=MeshCentral Agent\n[Service]\nExecStart=/usr/local/mesh/meshagent\nStandardOutput=null\nRestart=always\nRestartSec=3\n[Install]\nWantedBy=multi-user.target\nAlias=meshagent.service\n" > /lib/systemd/system/meshagent.service
126 else
127 - # Some distros have the systemd folder at a different place
127 + # Some distros have the systemd folder at a different place
128 if [ -d "/usr/lib/systemd/system/" ]
129 then
130 echo -e "[Unit]\nDescription=MeshCentral Agent\n[Service]\nExecStart=/usr/local/mesh/meshagent\nStandardOutput=null\nRestart=always\nRestartSec=3\n[Install]\nWantedBy=multi-user.target\nAlias=meshagent.service\n" > /usr/lib/systemd/system/meshagent.service
131 else
132 echo "Unable to find systemd folder."
133 fi
134 - fi
134 + fi
135 systemctl enable meshagent
136 systemctl start meshagent
137 - echo 'meshagent installed as systemd service.'
138 - echo 'To start service: sudo systemctl start meshagent'
139 - echo 'To stop service: sudo systemctl stop meshagent'
137 + echo 'meshagent installed as systemd service.'
138 + echo 'To start service: sudo systemctl start meshagent'
139 + echo 'To stop service: sudo systemctl stop meshagent'
140 elif [ $starttype -eq 3 ]
141 then
142 - # initd
143 - wget $url/meshagents?script=2 --no-check-certificate -O /etc/init.d/meshagent
144 - chmod +x /etc/init.d/meshagent
145 - # creates symlinks for rc.d
146 - update-rc.d meshagent defaults
147 - service meshagent start
148 - echo 'meshagent installed as init.d service.'
149 - echo 'To start service: sudo service meshagent start'
150 - echo 'To stop service: sudo service meshagent stop'
142 + # initd
143 + wget $url/meshagents?script=2 --no-check-certificate {{{noproxy}}}-O /etc/init.d/meshagent
144 + chmod +x /etc/init.d/meshagent
145 + # creates symlinks for rc.d
146 + update-rc.d meshagent defaults
147 + service meshagent start
148 + echo 'meshagent installed as init.d service.'
149 + echo 'To start service: sudo service meshagent start'
150 + echo 'To stop service: sudo service meshagent stop'
151 elif [ $starttype -eq 2 ]
152 - then
153 - # upstart
152 + then
153 + # upstart
154 echo -e "start on runlevel [2345]\nstop on runlevel [016]\n\nrespawn\n\nchdir /usr/local/mesh\nexec /usr/local/mesh/meshagent\n\n" > /etc/init/meshagent.conf
155 - service meshagent start
156 - echo 'meshagent installed as upstart/init.d service.'
157 - echo 'To start service: sudo service meshagent start'
158 - echo 'To stop service: sudo service meshagent stop'
159 - else
160 - # unknown
155 + service meshagent start
156 + echo 'meshagent installed as upstart/init.d service.'
157 + echo 'To start service: sudo service meshagent start'
158 + echo 'To stop service: sudo service meshagent stop'
159 + else
160 + # unknown
161 echo "Unknown Service Platform Type. (ie: init, systemd, etc)"
162 echo "Unable to install meshagent as service."
163 fi
164 - echo "Mesh agent started."
164 + echo "Mesh agent started."
165 else
166 echo "Unable to download mesh settings at: $url/meshsettings?id=$meshid."
167 fi
@@ -187,16 +187,17 @@ UninstallAgent() {
187 systemctl stop meshagent
188 else
189 if [ $starttype -eq 3 ]; then
190 - # initd
191 - service meshagent stop
192 - update-rc.d -f meshagent remove
193 - rm -f /sbin/meshcmd /etc/init.d/meshagent
194 - elif [ $starttype -eq 2 ]; then
195 - # upstart
196 - service meshagent stop
197 - rm -f /sbin/meshcmd
198 - rm -f /etc/init/meshagent.conf
199 - fi
190 + # initd
191 + service meshagent stop
192 + update-rc.d -f meshagent remove
193 + rm -f /sbin/meshcmd /etc/init.d/meshagent
194 + elif [ $starttype -eq 2 ]; then
195 + # upstart
196 + service meshagent stop
197 + rm -f /sbin/meshcmd
198 + rm -f /etc/init/meshagent.conf
199 + rm -f /etc/rc2.d/S20mesh /etc/rc3.d/S20mesh /etc/rc5.d/S20mesh
200 + fi
201 fi
202
203 if [ -e $installpath ]
meshcentral.js
+5 -2
@@ -1275,8 +1275,8 @@ function CreateMeshCentralServer(config, args) {
1275
1276 // List of possible mesh agent install scripts
1277 var meshAgentsInstallScriptList = {
1278 - 1: { id: 1, localname: 'meshinstall-linux.sh', rname: 'meshinstall.sh' },
1279 - 2: { id: 2, localname: 'meshinstall-initd.sh', rname: 'meshagent' }
1278 + 1: { id: 1, localname: 'meshinstall-linux.sh', rname: 'meshinstall.sh', linux: true },
1279 + 2: { id: 2, localname: 'meshinstall-initd.sh', rname: 'meshagent', linux: true }
1280 };
1281
1282 // Update the list of available mesh agents
@@ -1302,6 +1302,9 @@ function CreateMeshCentralServer(config, args) {
1302 var stats = null;
1303 try { stats = obj.fs.statSync(this.agentpath); } catch (e) { }
1304 if (stats != null) { obj.meshAgentInstallScripts[this.info.id].size = stats.size; }
1305 +
1306 + // Place Unit line breaks on Linux scripts if not already present.
1307 + if (obj.meshAgentInstallScripts[this.info.id].linux === true) { obj.meshAgentInstallScripts[this.info.id].data = obj.meshAgentInstallScripts[this.info.id].data.split('\r\n').join('\n') }
1308 });
1309 stream.info = meshAgentsInstallScriptList[scriptid];
1310 stream.agentpath = scriptpath;
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.2.9-m",
3 + "version": "0.2.9-n",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",