-
Notifications
You must be signed in to change notification settings - Fork 34
/
LinuxInstall.cs
164 lines (140 loc) · 5.4 KB
/
LinuxInstall.cs
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* FOG Service : A computer management client for the FOG Project
* Copyright (C) 2014-2022 FOG Project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
using System.IO;
using System.Linq;
using Zazzles;
namespace FOG
{
internal class LinuxInstall : IInstall
{
public bool PrepareFiles()
{
return true;
}
public bool Install()
{
if (Directory.Exists(GetLocation()))
Uninstall();
if (!Directory.Exists("/opt/"))
{
Directory.CreateDirectory("/opt/");
ProcessHandler.Run("chown", "root:root /opt/");
ProcessHandler.Run("chmod", "0755 /opt/");
}
Helper.ExtractFiles("/opt/", GetLocation());
var logLocation = Path.Combine(GetLocation(), "fog.log");
if (!File.Exists(logLocation))
File.Create(logLocation);
ProcessHandler.Run("chmod", "755 " + logLocation);
Helper.ExtractResource("FOG.Scripts.control.sh", Path.Combine(GetLocation(), "control.sh"), true);
ProcessHandler.Run("chmod", "755 " + Path.Combine(GetLocation(), "control.sh"));
return AddControlScripts();
}
public bool Install(string https, string tray, string server, string webRoot, string company, string rootLog, string location)
{
return Install();
}
public bool isSystemd()
{
var systemd = ProcessHandler.Run("pidof", "systemd");
return systemd == 0;
}
public bool isInitd()
{
var initd = ProcessHandler.Run("pidof", "init");
return initd == 0;
}
private bool AddControlScripts()
{
var systemd = isSystemd();
var initd = isInitd();
if (!systemd && !initd) return false;
if (systemd)
{
var path = "";
var path1 = "/lib/systemd/system";
var path2 = "/usr/lib/systemd/system";
if (Directory.Exists(path1))
path = path1;
else if (Directory.Exists(path2))
path = path2;
else
return false;
Helper.ExtractResource("FOG.Scripts.systemd", Path.Combine(path,"FOGService.service"), true);
ProcessHandler.Run("chmod", "755 " + Path.Combine(path,"FOGService.service"));
ProcessHandler.Run("systemctl", "enable FOGService.service");
}
else if (initd)
{
Helper.ExtractResource("FOG.Scripts.init-d", "/etc/init.d/FOGService", true);
ProcessHandler.Run("chmod", "755 /etc/init.d/FOGService");
if(ProcessHandler.Run("sysv-rc-conf", "FOGService on") != 0)
ProcessHandler.Run("chkconfig", "FOGService on");
}
return true;
}
public bool Configure()
{
return true;
}
public string GetLocation()
{
return "/opt/fog-service";
}
public void PrintInfo()
{
UniversalInstaller.PrintInfo("Systemd", isSystemd().ToString());
UniversalInstaller.PrintInfo("Initd", isInitd().ToString());
}
public bool Uninstall()
{
var systemd = isSystemd();
var initd = isInitd();
if (Directory.Exists(GetLocation()))
{
if (Settings.Location.Contains(GetLocation()))
{
var filePaths = Directory.GetFiles(GetLocation(),"*",SearchOption.TopDirectoryOnly);
foreach (var filePath in filePaths.Where(filePath => !filePath.ToLower().EndsWith("fog.log")))
{
File.Delete(filePath);
}
}
else
{
Directory.Delete(GetLocation(), true);
}
}
if (systemd)
ProcessHandler.Run("systemctl", "disable FOGService");
else if (initd)
{
ProcessHandler.Run("sysv-rc-conf", "FOGService off");
ProcessHandler.Run("chkconfig", "FOGService off");
}
if (File.Exists("/etc/init.d/FOGService"))
File.Delete("/etc/init.d/FOGService");
if (File.Exists("/lib/systemd/system/FOGService.service"))
File.Delete("/lib/systemd/system/FOGService.service");
if (File.Exists("/usr/lib/systemd/system/FOGService.service"))
File.Delete("/usr/lib/systemd/system/FOGService.service");
return true;
}
}
}