-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·155 lines (127 loc) · 4.53 KB
/
build.sh
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
#!/bin/bash
# Function to print messages with a timestamp
log() {
echo "$(date +'%Y-%m-%d %H:%M:%S') - $1"
}
# Function to detect the operating system
detect_os() {
case "$(uname -s)" in
Darwin)
echo "macos"
;;
Linux)
echo "linux"
;;
*)
echo "unsupported"
;;
esac
}
# Set the name of the application
NAME="Configurator"
# Determine the operating system
OS=$(detect_os)
if [ "$OS" == "unsupported" ]; then
log "Unsupported operating system. Exiting."
exit 1
fi
# Check if the Python virtual environment is already set up
if [ ! -f "env/bin/python" ] || [ ! -f "env/bin/python3" ] || [ ! -f "env/bin/pip" ]; then
log "Python virtual environment not found. Creating a new one..."
python3 -m venv env --system-site-packages
else
log "Python virtual environment found."
fi
# Activate the environment
source env/bin/activate
# Ensure that pip is updated
log "Updating pip..."
python -m pip install --upgrade pip
# Ensure the necessary packages are installed
log "Installing required packages..."
pip install pyinstaller sip importlib PySide6-Addons psutil chardet
pip install pyqt5 --config-settings --confirm-license= --verbose
# Check if the .spec file exists
SPEC_FILE="$NAME.spec"
ICON_FILE="src/icons/icon.icns"
# Cleanup: Remove the leftover dist/$NAME directory on macOS
log "Cleaning up..."
if [ -d "dist/$NAME" ]; then
rm -rf "dist/$NAME"
fi
if [ -f "$SPEC_FILE" ]; then
rm -f "$SPEC_FILE"
fi
log ".spec file not found. Generating a new one with Configurator..."
if [ "$OS" == "macos" ]; then
pyinstaller --windowed --name "$NAME" src/configurator.py
elif [ "$OS" == "linux" ]; then
pyinstaller --onefile --name "$NAME" src/configurator.py
fi
# Ensure the spec file now exists
if [ ! -f "$SPEC_FILE" ]; then
log "Failed to create .spec file. Exiting."
exit 1
fi
log "Generated .spec file: $SPEC_FILE"
# Update the .spec file to include the custom icon, data files, and hidden imports
log "Updating the .spec file to include the custom icon, data files, and hidden imports..."
if [ "$OS" == "macos" ]; then
sed -i '' "s|icon=None|icon='$ICON_FILE'|g" $SPEC_FILE
sed -i '' "/Analysis/s/(.*)/\0, hiddenimports=['PyQt5.QtSvg']/" $SPEC_FILE
sed -i '' "/a.datas +=/a \\
datas=[('src/styles', 'styles'), ('src/icons', 'icons'), ('src/img', 'img'), ('src/lib', 'lib')],
" $SPEC_FILE
elif [ "$OS" == "linux" ]; then
sed -i "s|icon=None|icon='$ICON_FILE'|g" $SPEC_FILE
sed -i "/Analysis/s/(.*)/\0, hiddenimports=['PyQt5.QtSvg']/" $SPEC_FILE
sed -i "/a.datas +=/a \\
datas=[('src/styles', 'styles'), ('src/icons', 'icons'), ('src/img', 'img'), ('src/lib', 'lib')],
" $SPEC_FILE
fi
# Build the project with PyInstaller using the updated .spec file
log "Building the project with PyInstaller..."
pyinstaller --noconfirm $SPEC_FILE
# Copy resources into the appropriate location
if [ "$OS" == "macos" ]; then
APP_BUNDLE="dist/$NAME.app/Contents/Resources"
log "Copying resources into the app bundle..."
mkdir -p "$APP_BUNDLE/styles"
mkdir -p "$APP_BUNDLE/img"
mkdir -p "$APP_BUNDLE/icons"
mkdir -p "$APP_BUNDLE/lib"
cp -R src/styles/* "$APP_BUNDLE/styles/"
cp -R src/img/* "$APP_BUNDLE/img/"
cp -R src/icons/* "$APP_BUNDLE/icons/"
cp -R src/lib/* "$APP_BUNDLE/lib/"
else
log "Linux build does not require copying resources to a separate directory, as it is a single-file executable."
# Note: If you need to bundle resources within the executable, adjust the PyInstaller options to include those resources
fi
# Create a directory to store the final output based on the OS
FINAL_DIR="dist/$OS"
if [ -d "$FINAL_DIR" ]; then
rm -rf "$FINAL_DIR"
fi
mkdir -p "$FINAL_DIR"
# Move the built application or executable to the appropriate directory
if [ "$OS" == "macos" ]; then
log "Moving the .app bundle to the $FINAL_DIR directory..."
mv "dist/$NAME.app" "$FINAL_DIR/"
# Create a DMG image
log "Creating a DMG image for macOS..."
DMG_NAME="$FINAL_DIR/$NAME.dmg"
hdiutil create "$DMG_NAME" -volname "$NAME" -srcfolder "$FINAL_DIR/$NAME.app" -ov -format UDZO
log "DMG image created at $DMG_NAME"
else
log "Moving the executable to the $FINAL_DIR directory..."
mv "dist/$NAME" "$FINAL_DIR/"
fi
# Cleanup: Remove the leftover dist/$NAME directory on macOS
if [ -d "dist/$NAME" ]; then
log "Cleaning up the dist directory..."
rm -rf "dist/$NAME"
fi
log "Build completed successfully."
# Deactivate the virtual environment
deactivate