Skip to content

Commit

Permalink
Added and improved build scripts (build-app.sh, build-dmg.sh), Severa…
Browse files Browse the repository at this point in the history
…l small fixes and code cleanup
  • Loading branch information
Lennolium committed Sep 29, 2023
1 parent 1c7e3d6 commit b836f88
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 75 deletions.
118 changes: 118 additions & 0 deletions build-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/bin/sh

# Define colors for log
_info() { echo "\033[1m[INFO]\033[0m $1" ; }
_ok() { echo "\033[32m[OK]\033[0m $1" ; }
_error() { echo "\033[31m[ERROR]\033[0m $1" ; }
_logo() { echo "\033[1m $1\033[0m" ; }

# Check if architecture is x86_64, because some dependencies are
# throwing errors on arm64.
if [ "$(uname -m)" = arm64 ]; then
_error "You are using arm64 architecture. This script will switch to x86_64 now."
_error "After Terminal-Relaunch, you need to run this script again:"
_logo "---> ./build-app.sh <---"
_info "Press any key to continue ..."
read -r wait
exec arch -x86_64 /bin/zsh
fi

# Header
echo ""
echo ""
_logo " █▌ ▀▀▀▀▀▀ ║█ ╫█ ▐█µ ▐█ ▄██▀▀██▌ ██ ▀└ █▌ ╒█▌ █µ █▌ "
_logo " ▐█ ███▌ ██ ████ ██ ██ ╟█ ▐█ ▐█ ║█ ╫█ ║██▌ ╓███ "
_logo " ██ ▀▀▀▀▀▀ ╒█Γ└██▓█ █▌ ██▓█▌▐█ ██ ██ ██ ██ ██ ███▀ ██ "
_logo "┌▀ ██ ▀██ ║█ ╙██ └██ ╓██ █▌ ╒█▌ ██ ██ ╒█▌ ╙ ╒█Γ "
_logo " -▀▀▀▀ ╝▀▀▀▀▀▀ ▀▀ ▀ ▀▀ ▀ ▀▀█▀▀ ╘▀▀▀▀▀ ╝▀ ▀██▀ ╝▀ ╝▀ "
_logo " "
_logo " S W I F T G U A R D B U I L D S C R I P T "
_logo " ------------------------------------------------------------------------- "
echo ""
echo ""

# Ask if the script should start with building the dmg.
_info "This script will build an .app file of swiftGuard. \nContinue? (y/n)"
read -r response
if [ "$response" = "y" ]; then
_ok "Let us begin!"
else
_error "Script aborted."
exit;
fi

# Check if Python3 is installed and install it if not.
_info "Checking and installing requirements ..."
if test ! "$(which python3)"; then
_info "Python3 is not installed! Installing with Homebrew ..."
/bin/bash -c \
"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew update
brew install python3
else
_ok "Python3 is installed."
fi

# Check if architecture is right
_info "Checking if architecture is right (using uname)
If you are using arm64 architecture, this script will switch to x86_64 now."
if [ `uname -m` = arm64 ]; then
_error "You are using arm64 architecture. This script will switch to x86_64 now."
_error "After Terminal-Relaunch, you need to run this script again:\n./build-app.sh"
_info "Press any key to continue ..."
read -r wait
exec arch -x86_64 /bin/zsh
fi

# Checking for needed source files.
_info "Checking if src/swiftGuard is present (needed for building)."
if [ ! -d "src/swiftGuard" ]; then
_error "No src/swiftGuard directory found. Please clone the whole repository first."
exit 1
fi

# Creating dist folder.
mkdir -p dist/

# Delete the content of dist folder (to remove old .app builds).
_info "Deleting old builds in /dist folder (all files get deleted!)."
rm -R dist/*

# Creating build folder.
mkdir -p build/

# Delete the content of build folder (to remove old builds).
_info "Deleting old builds in /build folder (all files get deleted!)."
rm -R build/*

# Check if venv is created and do so if not.
if ! [ -d "./venv" ] ; then
_info "Creating virtual environment, so we do not pollute your system."
python3 -m venv venv
else
_ok "Looks like a virtual environment (venv) is already created."
fi

# Activate venv and install requirements.
source venv/bin/activate
pip install -r requirements.txt
pip install --upgrade PyInstaller pyinstaller-hooks-contrib

# Build the app.
_info "Building the .app file. This can take a while ..."
if pyinstaller "pyinstaller.spec"
then
_ok "Pyinstaller successfully created build."
else
_error "Build failed!"
exit 1
fi

# Finished: Open finder with the dmg folder.
_ok "swiftGuard.app was successfully created!"
_ok "SCRIPT FINISHED!"
_logo "--> Press any key to open dist folder and exit script... <--"
read -r exit
cd dist || exit
open .
exit
100 changes: 81 additions & 19 deletions build-dmg.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,67 @@
#!/bin/sh

echo "[INFO] Creating needed and temp folders ..."
# Define colors for log
_info() { echo "\033[1m[INFO]\033[0m $1" ; }
_ok() { echo "\033[32m[OK]\033[0m $1" ; }
_error() { echo "\033[31m[ERROR]\033[0m $1" ; }
_logo() { echo "\033[1m $1\033[0m" ; }

# Header
echo ""
echo ""
_logo " █▌ ▀▀▀▀▀▀ ║█ ╫█ ▐█µ ▐█ ▄██▀▀██▌ ██ ▀└ █▌ ╒█▌ █µ █▌ "
_logo " ▐█ ███▌ ██ ████ ██ ██ ╟█ ▐█ ▐█ ║█ ╫█ ║██▌ ╓███ "
_logo " ██ ▀▀▀▀▀▀ ╒█Γ└██▓█ █▌ ██▓█▌▐█ ██ ██ ██ ██ ██ ███▀ ██ "
_logo "┌▀ ██ ▀██ ║█ ╙██ └██ ╓██ █▌ ╒█▌ ██ ██ ╒█▌ ╙ ╒█Γ "
_logo " -▀▀▀▀ ╝▀▀▀▀▀▀ ▀▀ ▀ ▀▀ ▀ ▀▀█▀▀ ╘▀▀▀▀▀ ╝▀ ▀██▀ ╝▀ ╝▀ "
_logo " "
_logo " S W I F T G U A R D B U I L D S C R I P T "
_logo " ------------------------------------------------------------------------- "
echo ""
echo ""

# Ask if the script should start with building the dmg.
_info "This script will build a dmg file for swiftGuard. Make sure you have built a swiftGuard.app and it is in the /dist folder.\nContinue? (y/n)"
read -r response
if [ "$response" = "y" ]; then
_ok "Let us begin!"
else
_error "Script aborted."
exit;
fi

# Check if homebrew is installed and install it if not.
_info "Checking if homebrew is installed ..."
if test ! "$(which brew)"; then
_info "Installing homebrew now ..."
/bin/bash -c \
"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew update
else
_ok "Homebrew is installed."
brew update
fi

# Check if create-dmg is installed and install it if not.
_info "Checking if create-dmg is installed ..."
if test ! "$(which create-dmg)"; then
_info "Installing create-dmg now ..."
brew install create-dmg
else
brew upgrade create-dmg
_ok "create-dmg is installed."
fi

# Checking if swiftGuard.app is in /dist folder.
_info "Checking if swiftGuard.app is in /dist folder ..."

if [ ! -d "dist/swiftGuard.app" ]; then
_error "swiftGuard.app not found in /dist folder. Please build the app first (using build-app.sh)."
exit 1
fi

# Create a folder dmg to copy the finished .dmg in it.
_info "Creating needed folders ..."
mkdir -p dmg/

# Create a temp folder to copy the .app file to.
Expand All @@ -11,15 +70,13 @@ mkdir -p dist/dmg-temp
# Copy the .app bundle to the dmg-temp folder.
cp -R "dist/swiftGuard.app" dist/dmg-temp

echo "[INFO] Deleting content of /dmg folder"

# Delete the content of /dmg folder (to remove old dmgs).
_info "Making sure there is no content in /dmg folder."
rm -R dmg/*

echo "[INFO] DMG building started ..."

# Create the DMG. (optional: --eula "LICENSE" \)
create-dmg \
_info ".dmg building started. This can take a while ..."
if create-dmg \
--volname "swiftGuard" \
--volicon "img/dmg-icon/[email protected]" \
--background "img/dmg-bg/[email protected]" \
Expand All @@ -31,23 +88,28 @@ create-dmg \
--app-drop-link 480 170 \
"dmg/swiftGuard.dmg" \
"dist/dmg-temp/"

echo "[INFO] Deleting temp files and folders ..."

# Empty the dmg-temp folder.
then
_ok "create-dmg successfully created .dmg file without errors."
else
_error "create-dmg exited with errors. No .dmg created."
exit 1
fi

# Empty and deleting the dmg-temp folder.
_info "Deleting temp files and folders ..."
rm -R dist/dmg-temp/*

# Delete the dmg-temp folder.
rm -r dist/dmg-temp

echo "[INFO] Generating sha256 checksum file ..."

# Generate sha256 hash file of installer and check it.
cd dmg
_info "Generating sha256 checksum file of dmg..."
cd dmg || exit
sha256sum "swiftGuard.dmg" > SHA256SUM
_info "Validate sha256 checksum ..."
sha256sum -c SHA256SUM


echo "[INFO] swiftGuard.dmg and checksum.sha256 created in /dmg folder"

echo "[INFO] FINISHED!"
# Finished: Open finder with the dmg folder.
_ok "swiftGuard.dmg and checksum.sha256 created in /dmg folder"
_ok "SCRIPT FINISHED! \nPress any key to open /dmg folder and exit..."
read -r exit
open .
exit
File renamed without changes.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ PySide6==6.5.2
darkdetect==0.8.0
black==23.9.1
bandit==1.7.5
pyinstaller==6.0.0
pyinstaller-hooks-contrib==2023.9
Loading

0 comments on commit b836f88

Please sign in to comment.