2021-08-27 17:19:18 +02:00
|
|
|
#!/usr/bin/env bash
|
2021-02-24 01:54:12 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# The MIT License (MIT)
|
|
|
|
#
|
|
|
|
# Copyright (C) 2021 Joe Testa (jtesta@positronsecurity.com)
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# build_windows_executable.sh
|
|
|
|
#
|
|
|
|
# Builds a Windows executable using PyInstaller.
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
PLATFORM="$(uname -s)"
|
|
|
|
|
|
|
|
# This script is intended for use on Cygwin only.
|
2023-09-05 19:14:21 +02:00
|
|
|
case "${PLATFORM}" in
|
2021-02-24 01:54:12 +01:00
|
|
|
CYGWIN*) ;;
|
|
|
|
*)
|
2023-09-05 19:14:21 +02:00
|
|
|
echo "Platform not supported (${PLATFORM}). This must be run in Cygwin only."
|
2021-08-27 17:19:18 +02:00
|
|
|
exit 1
|
|
|
|
;;
|
2021-02-24 01:54:12 +01:00
|
|
|
esac
|
|
|
|
|
|
|
|
# Ensure that Python 3.x is installed.
|
|
|
|
if [[ "$(python -V)" != "Python 3."* ]]; then
|
|
|
|
echo "Python v3.x not found. Install the latest stable version from: https://www.python.org/"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-04-26 02:14:49 +02:00
|
|
|
# Install/update package dependencies.
|
2023-04-27 03:55:40 +02:00
|
|
|
echo "Installing/updating pyinstaller and colorama packages..."
|
|
|
|
pip install -U pyinstaller colorama
|
2023-04-26 02:14:49 +02:00
|
|
|
echo
|
2021-02-24 01:54:12 +01:00
|
|
|
|
2021-08-26 16:39:11 +02:00
|
|
|
# Prompt for the version to release.
|
|
|
|
echo -n "Enter the version to release, using format 'vX.X.X': "
|
|
|
|
read -r version
|
|
|
|
|
|
|
|
# Ensure that entered version fits required format.
|
|
|
|
if [[ ! $version =~ ^v[0-9]\.[0-9]\.[0-9]$ ]]; then
|
|
|
|
echo "Error: version string does not match format vX.X.X!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Verify that version is correct.
|
|
|
|
echo -n "Version will be set to '${version}'. Is this correct? (y/n): "
|
|
|
|
read -r yn
|
|
|
|
echo
|
|
|
|
|
|
|
|
if [[ $yn != "y" ]]; then
|
|
|
|
echo "Build cancelled."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Reset any local changes made to globals.py from a previous run.
|
|
|
|
git checkout src/ssh_audit/globals.py 2> /dev/null
|
|
|
|
|
2021-02-24 01:54:12 +01:00
|
|
|
# Update the man page.
|
|
|
|
./update_windows_man_page.sh
|
2023-09-05 19:14:21 +02:00
|
|
|
retval=$?
|
|
|
|
if [[ ${retval} != 0 ]]; then
|
2021-02-24 01:54:12 +01:00
|
|
|
echo "Failed to run ./update_windows_man_page.sh"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Do all operations from this point from the main source directory.
|
2023-09-05 19:14:21 +02:00
|
|
|
pushd src/ssh_audit || exit > /dev/null
|
2021-02-24 01:54:12 +01:00
|
|
|
|
2021-08-26 16:39:11 +02:00
|
|
|
# Delete the existing VERSION variable and add the value that the user entered, above.
|
|
|
|
sed -i '/^VERSION/d' globals.py
|
|
|
|
echo "VERSION = '$version'" >> globals.py
|
|
|
|
|
|
|
|
# Delete cached files if they exist from a prior run.
|
|
|
|
rm -rf dist/ build/ ssh-audit.spec
|
2021-02-24 01:54:12 +01:00
|
|
|
|
2021-08-26 16:39:11 +02:00
|
|
|
# Create a hard link from ssh_audit.py to ssh-audit.py.
|
2021-02-24 01:54:12 +01:00
|
|
|
if [[ ! -f ssh-audit.py ]]; then
|
|
|
|
ln ssh_audit.py ssh-audit.py
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo -e "\nRunning pyinstaller...\n"
|
|
|
|
pyinstaller -F --icon ../../windows_icon.ico ssh-audit.py
|
|
|
|
|
|
|
|
if [[ -f dist/ssh-audit.exe ]]; then
|
|
|
|
echo -e "\nExecutable created in $(pwd)/dist/ssh-audit.exe\n"
|
2021-08-26 16:39:11 +02:00
|
|
|
else
|
|
|
|
echo -e "\nFAILED to create $(pwd)/dist/ssh-audit.exe!\n"
|
|
|
|
exit 1
|
2021-02-24 01:54:12 +01:00
|
|
|
fi
|
|
|
|
|
2021-08-25 20:24:10 +02:00
|
|
|
# Ensure that the version string doesn't have '-dev' in it.
|
2023-09-05 19:14:21 +02:00
|
|
|
dist/ssh-audit.exe | grep -E 'ssh-audit.exe v.+\-dev' > /dev/null
|
|
|
|
retval=$?
|
|
|
|
if [[ ${retval} == 0 ]]; then
|
2021-08-25 20:24:10 +02:00
|
|
|
echo -e "\nError: executable's version number includes '-dev'."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-08-26 16:47:43 +02:00
|
|
|
# Remove the cache files created during the build process, along with the link we created, above.
|
|
|
|
rm -rf build/ ssh-audit.spec ssh-audit.py
|
2021-02-24 01:54:12 +01:00
|
|
|
|
2021-08-26 16:39:11 +02:00
|
|
|
# Reset the changes we made to globals.py.
|
|
|
|
git checkout globals.py 2> /dev/null
|
|
|
|
|
2023-09-05 19:14:21 +02:00
|
|
|
popd || exit > /dev/null
|
2021-02-24 01:54:12 +01:00
|
|
|
exit 0
|