import windows packaging helpers
authorNeil <neil@dip.sun.ac.za>
Fri, 16 May 2014 13:57:20 +0000 (15:57 +0200)
committerNeil <neil@dip.sun.ac.za>
Fri, 16 May 2014 15:50:15 +0000 (17:50 +0200)
packaging/makensis [new file with mode: 0755]
packaging/naja.nsi [new file with mode: 0644]
packaging/wine-py2exe [new file with mode: 0755]

diff --git a/packaging/makensis b/packaging/makensis
new file mode 100755 (executable)
index 0000000..03394a6
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/sh
+# Usage: makensis
+
+NSI_FILE="`dirname $0`/naja.nsi"
+WS_VERSION=`sed -ne 's/VERSION_STR = "\(.*\)"/\1/p' setup.py`
+TMP_NSI="$NSI_FILE.tmp"
+
+# We include the pre-SP1 version of the MS redistibutable package  - there are
+# contradictory reports of whether the SP1 release will work with python 2.7,
+# so I haven't tested it. Thiis version works for me
+# This is all for the 32 bit version
+if [ ! -f "dist/vcredist_x86.exe" ]; then
+   echo "Please copy the required vcredist_x86.exe version into dist/"
+   echo "(version downloaded from http://www.microsoft.com/downloads/en/details.aspx?FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1b)"
+   exit
+else
+   # md5sum from 2011-06-25 - MS haven't changed this package in some
+   # time, so hopefully this will stay valid
+   EXPECTED="b936f0f378b9a35489353e878154e899"
+   MD5=`md5sum dist/vcredist_x86.exe | cut -d " " -f 1`
+   if [ "$MD5" != "$EXPECTED" ]; then
+      echo "Unexpected md5sum for vcredist_x86.exe"
+      echo "expected $EXPECTED, got $MD5"
+      exit
+   fi
+fi
+
+cp "$NSI_FILE" "$TMP_NSI"
+sed -i -e "s#\\(\\s*!define WS_VERSION\\).*#\\1 \"$WS_VERSION\"#" "$TMP_NSI"
+makensis "$TMP_NSI"
+rm "$TMP_NSI"
diff --git a/packaging/naja.nsi b/packaging/naja.nsi
new file mode 100644 (file)
index 0000000..12ef327
--- /dev/null
@@ -0,0 +1,143 @@
+; Compile with ./scripts/makensis ./scripts/naja.nsi .
+; You'll need to have previously run wine-py2exe
+
+  !include "MUI.nsh"
+
+; Application Details
+
+  !define WS_VERSION "0.0.0" ; set by makensis scripts
+  !define WS_UNPACK "naja-${WS_VERSION}"
+  !define DIST_FOLDER "../dist"
+
+  Name "Robolock"
+  OutFile "${DIST_FOLDER}\naja-${WS_VERSION}.exe"
+  InstallDir "$PROGRAMFILES\Robolock-${WS_VERSION}"
+
+; Interface Settings
+
+  !define MUI_ABORTWARNING
+
+  !define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\arrow-install.ico"
+  !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\arrow-uninstall.ico"
+
+  !define MUI_HEADERIMAGE
+  !define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\orange.bmp"
+  !define MUI_HEADERIMAGE_UNBITMAP "${NSISDIR}\Contrib\Graphics\Header\orange-uninstall.bmp"
+
+; Dependencies
+
+  !define COMBINED_LICENSE "../LICENSE.txt"
+  !define WS_PY2EXE_ZIP "naja-${WS_VERSION}.zip"
+  !define WS_ICON "../data/icons/robolock.ico"
+  !define WS_WINDOWS_ICON "data\icons\robolock.ico"
+  !define VCREDIST "vcredist_x86.exe"
+  !define VCREDIST_KEY "{FF66E9F6-83E7-3A3E-AF14-8DE9A809A6A4}"
+  !define UNINSTALLER "Uninstaller.exe"
+
+; Pages
+
+  !insertmacro MUI_PAGE_LICENSE "${COMBINED_LICENSE}"
+  !insertmacro MUI_PAGE_DIRECTORY
+  !insertmacro MUI_PAGE_INSTFILES
+
+  !insertmacro MUI_UNPAGE_CONFIRM
+  !insertmacro MUI_UNPAGE_INSTFILES
+
+; Languages
+
+  !insertmacro MUI_LANGUAGE "English"
+
+; Other Stuff
+
+  Icon "${WS_ICON}"
+  SetCompress off ; all the big stuff is already compressed
+
+; Installer Sections
+
+Section "vcredist"
+
+  SetOutPath "$INSTDIR"
+  File "${DIST_FOLDER}\${VCREDIST}"
+   ; Check if it's already installed by checking for the uninstall key
+   ; Idea and key value to check taken post and comments at:
+   ; http://blogs.msdn.com/b/astebner/archive/2009/01/29/9384143.aspx
+
+   ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${VCREDIST_KEY}" UninstallString
+   ; NSIS docs say if the key doesn't exist, we get an error and an empty string
+   IfErrors install done
+
+install:
+   ; Runs install with progress bar and no cancel button
+   ; Details taken from
+   ; http://blogs.msdn.com/b/astebner/archive/2010/10/18/9513328.aspx
+
+   DetailPrint "Installing required MS runtime libraries"
+   ExecWait "$INSTDIR/${VCREDIST} /qb!"
+
+done:
+
+   DetailPrint "MS runtime libraries already installed, skipping"
+
+SectionEnd
+
+Section "Robolock"
+  SetOutPath "$INSTDIR"
+
+  WriteUninstaller "$INSTDIR\${UNINSTALLER}"
+
+  File "${DIST_FOLDER}\${WS_PY2EXE_ZIP}"
+  File "${WS_ICON}"
+
+  ZipDLL::extractall "$INSTDIR\${WS_PY2EXE_ZIP}" "$INSTDIR"
+  Delete "$INSTDIR\${WS_PY2EXE_ZIP}"
+
+  CreateDirectory "$SMPROGRAMS\Robolock"
+
+  # link.lnk target.exe
+  #   parameters icon.file icon_index_number start_options
+  #   keyboard_shortcut description
+
+  CreateShortCut "$SMPROGRAMS\Robolock\Robolock ${WS_VERSION}.lnk" "$INSTDIR\${WS_UNPACK}\naja.exe" \
+     "" "$INSTDIR\${WS_UNPACK}\${WS_WINDOWS_ICON}" "" SW_SHOWNORMAL \
+     "" "Robolock"
+
+  CreateShortCut "$SMPROGRAMS\Robolock\Uninstall Robolock ${WS_VERSION}.lnk" "$INSTDIR\${UNINSTALLER}" \
+     "" "" "" SW_SHOWNORMAL \
+     "" "Uninstall Robolock"
+
+SectionEnd
+
+UninstallText "This will uninstall Robolock ${WS_VERSION}."
+UninstallIcon "${WS_ICON}"
+
+Section "Uninstall"
+  ; Delete files not deleted during install
+
+  Delete "$INSTDIR\${WS_ICON}"
+
+  ; Remove py2exe folder
+  RMDir /r /REBOOTOK "$INSTDIR\${WS_UNPACK}"
+
+  ; Remove shortcut links
+  Delete "$SMPROGRAMS\Robolock\Robolock ${WS_VERSION}.lnk"
+  Delete "$SMPROGRAMS\Robolock\Uninstall Robolock ${WS_VERSION}.lnk"
+
+  ; Remove shortcut folder if no links left
+  IfFileExists "$SMPROGRAMS\Robolock\*.lnk" shortcuts_exist 0
+    RMDir /REBOOTOK "$SMPROGRAMS\Robolock"
+  shortcuts_exist:
+
+  ; Final Clean up (no point doing this while the uninstall is incomplete)
+  RMDir /r /REBOOTOK $INSTDIR
+
+  ; Offer to reboot if needed
+  IfRebootFlag 0 noreboot
+    MessageBox MB_YESNO "A reboot is required to finish the uninstallation. Do you wish to reboot now?" IDNO noreboot
+    Reboot
+  noreboot:
+
+  ; TODO: We don't touch the vcredist stuff, since we can't tell a) if we were
+  ; the ones who installed it and b) if anything else needs it. This may cause
+  ; cruft on the users system, so should we tell the user?
+
+SectionEnd
diff --git a/packaging/wine-py2exe b/packaging/wine-py2exe
new file mode 100755 (executable)
index 0000000..d8746c8
--- /dev/null
@@ -0,0 +1,73 @@
+#!/bin/sh
+# wine-py2exe
+#
+# Usage: wine-py2exe
+
+WS_VERSION=`sed -nre 's/VERSION_STR = "(.*)"/\1/p' setup.py`
+BUILD_FOLDER="naja-${WS_VERSION}"
+ZIP_NAME="${BUILD_FOLDER}.zip"
+PY2EXE_LOG="py2exe.log"
+
+WINE_PYTHON=`winepath "C:/Python27"`
+WINE_SYS32=`winepath "C:/windows/system32"`
+
+#
+# Run py2exe build under wine
+#
+
+echo "=== Running wine python setup.py ==="
+echo ""
+echo "  Robolock version: ${WS_VERSION}"
+echo "  Writing log to ${PY2EXE_LOG}."
+echo ""
+echo "  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
+echo "  WARNING: After running please fix the naja.exe"
+echo "           checksum and executable size using PETools!"
+echo "  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
+echo ""
+
+rm -rf "dist/${BUILD_FOLDER}"
+mkdir -p "dist/${BUILD_FOLDER}"
+rm -rf "dist/${ZIP_NAME}"
+
+wine python setup.py py2exe >${PY2EXE_LOG} 2>&1
+
+#
+# Copy dependencies py2exe missed
+#
+
+echo "=== Copying dependencies that py2exe missed ==="
+echo ""
+
+DEST="dist/${BUILD_FOLDER}"
+
+cp -v "${WINE_PYTHON}/python27.dll" "${DEST}"
+
+echo "'data' -> '${DEST}/data'"
+cp -R data ${DEST}/data
+
+echo "'${WINE_PYTHON}/Lib/site-packages/pygame' -> '${DEST}'"
+rm -rf "${DEST}/pygame"
+cp -R "${WINE_PYTHON}/Lib/site-packages/pygame" "${DEST}"
+rm -rf "${DEST}/pygame/examples" "${DEST}/pygame/tests" "${DEST}/pygame/docs"
+
+#
+# create zip file
+#
+
+echo "=== Creating zip of patched py2exe dist folder ==="
+echo ""
+echo "  Zip file: dist/${ZIP_NAME}"
+echo "  Build folder: dist/${BUILD_FOLDER}"
+echo ""
+
+cd dist
+rm -f "$ZIP_NAME"
+zip -r -q "$ZIP_NAME" "$BUILD_FOLDER"
+cd ..
+
+echo "=== Done ==="
+echo ""
+echo -n "  "; du -sh dist/${ZIP_NAME}
+echo -n "  "; du -sh dist/${BUILD_FOLDER}
+echo ""