-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_installer.py
More file actions
210 lines (180 loc) · 6.83 KB
/
build_installer.py
File metadata and controls
210 lines (180 loc) · 6.83 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env python3
"""
Build script for Infrastructure Agent with installer
"""
import subprocess
import sys
import os
import shutil
import json
from pathlib import Path
def install_dependencies():
"""Install required dependencies"""
print("Installing dependencies...")
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", "cx_freeze"])
print("Dependencies installed successfully")
return True
except subprocess.CalledProcessError as e:
print(f"Error installing dependencies: {e}")
return False
def create_license_file():
"""Create LICENSE.txt file if it doesn't exist"""
license_path = Path("LICENSE.txt")
if not license_path.exists():
print("Creating LICENSE.txt file...")
license_content = """Infrastructure Agent License
=========================
Copyright (c) 2025 Infrastructure Monitoring
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
with open(license_path, 'w') as f:
f.write(license_content)
print("LICENSE.txt created successfully")
else:
print("LICENSE.txt already exists")
return True
def build_executable():
"""Build the executable using cx_Freeze"""
print("Building executable...")
try:
# Run cx_Freeze setup
result = subprocess.run([
sys.executable, "setup.py", "build"
], capture_output=True, text=True)
if result.returncode == 0:
print("Executable built successfully")
return True
else:
print(f"Error building executable: {result.stderr}")
return False
except Exception as e:
print(f"Error during build process: {e}")
return False
def prepare_files():
"""Prepare files for installer"""
print("Preparing files for installer...")
try:
# Create dist directory if it doesn't exist
dist_dir = Path("dist")
dist_dir.mkdir(exist_ok=True)
# Copy required files to dist directory
required_files = [
"config.json",
"hosts.txt",
"agentlogo.ico",
"startup_agent.bat",
"run_agent.bat",
"LICENSE.txt"
]
for file in required_files:
if os.path.exists(file):
shutil.copy2(file, dist_dir / file)
print(f"Copied {file} to dist directory")
return True
except Exception as e:
print(f"Error preparing files: {e}")
return False
def create_installer():
"""Create the installer using Inno Setup"""
print("Creating installer...")
try:
# Check if Inno Setup compiler is available
compiler_path = r"C:\Program Files (x86)\Inno Setup 6\ISCC.exe"
if not os.path.exists(compiler_path):
print("Inno Setup compiler not found. Please install Inno Setup 6.")
print("Download from: http://www.jrsoftware.org/isinfo.php")
return False
# Run Inno Setup compiler
result = subprocess.run([
compiler_path, "setup.iss"
], capture_output=True, text=True)
if result.returncode == 0:
print("Installer created successfully")
print("Installer location: InfraAgentSetup.exe")
return True
else:
print(f"Error creating installer: {result.stderr}")
return False
except Exception as e:
print(f"Error during installer creation: {e}")
return False
def update_config_with_user_input():
"""Update config file with user input during build process"""
print("Updating configuration...")
try:
config_path = Path("config.json")
if config_path.exists():
# Read existing config
with open(config_path, 'r') as f:
config = json.load(f)
# Update with build-time values (these could be passed as arguments)
# For now, we'll keep the existing values but ensure the structure is correct
if 'servers' not in config:
config['servers'] = {
"development": "http://localhost:3001",
"production": "https://10.1.32.66"
}
if 'auth' not in config:
config['auth'] = {
"email": "infraagent@localhost.com",
"password": "Infraagent@2025"
}
# Write updated config
with open(config_path, 'w') as f:
json.dump(config, f, indent=4)
print("Configuration updated successfully")
return True
else:
print("Config file not found")
return False
except Exception as e:
print(f"Error updating configuration: {e}")
return False
def main():
print("Infrastructure Agent Build Script")
print("=" * 40)
# Create license file if needed
if not create_license_file():
print("Failed to create license file")
return False
# Install dependencies
if not install_dependencies():
print("Failed to install dependencies")
return False
# Prepare files
if not prepare_files():
print("Failed to prepare files")
return False
# Update configuration
if not update_config_with_user_input():
print("Failed to update configuration")
return False
# Build executable
if not build_executable():
print("Failed to build executable")
return False
# Create installer
if not create_installer():
print("Failed to create installer")
return False
print("\nBuild process completed successfully!")
print("Installer created: InfraAgentSetup.exe")
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)