Skip to content

Instantly share code, notes, and snippets.

@qlrd
Last active July 20, 2022 14:23
Show Gist options
  • Save qlrd/9be0143b54fa2645eeb26c1f95bc1356 to your computer and use it in GitHub Desktop.
Save qlrd/9be0143b54fa2645eeb26c1f95bc1356 to your computer and use it in GitHub Desktop.
krux windows installer (WIP)

Usage to build windows installer on Unix like OS

Execute

$> ./krux build <device>
$> ./krux build-release
$> ./krux build-win-installer
``
FROM debian:buster
ARG VERSION
COPY ./README.md /src/README.md
COPY ./LICENSE.md /src/LICENSE.md
COPY ./docs/img/favicon.png /src/favicon.png
COPY ./krux-v$VERSION/ktool-win.exe /src/ktool-win.exe
COPY ./krux-v$VERSION/maixpy_m5stickv/firmware.bin /src/maixpy_m5stickv/firmware.bin
COPY ./krux-v$VERSION/maixpy_m5stickv/kboot.kfpkg /src/maixpy_m5stickv/kbook.kfpkg
COPY ./krux-inst.nsi /src/krux-inst.nsi
RUN apt-get install --no-install-recommends -y -q nsis
RUN sed -i 's/%VERSIONMAJOR/'$(echo $VERSION | cut -d. -f1)'/g' /src/krux-inst.nsi \
sed -i 's/%VERSIONMINOR/'$(echo $VERSION | cut -d. -f2)'/g' /src/krux-inst.nsi \
sed -i 's/%VERSIONMAJOR/'$(echo $VERSION | cut -d. -f1)'/g' /src/krux-inst.nsi
RUN makensis -V4 /src/krux-inst.nsi
# The MIT License (MIT)
# Copyright (c) 2021 Tom J. Sun
# 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.
#Basic definitions
!define APPNAME "Krux"
!define COMPANYNAME "Selfcustody"
!define DESCRIPTION "Krux is an open-source DIY hardware signer for Bitcoin that can sign for multisignature and single-key wallets"
!define APPSHORTNAME "krux"
!define VERSIONMAJOR %VERSIONMAJOR
!define VERSIONMINOR %VERSIONMINOR
!define VERSIONBUILD %VERSIONBUILD
!define HELPURL "https://selfcustody.github.io/krux/"
!define UPDATEURL "https://github.com/selfcustody/krux/releases"
!define ABOUTURL "https://github.com/selfcustody/krux/blob/main/README.md"
# This is the size (in kB) of all the files copied into "Program Files"
# to calculate, use `du -cb <files> | awk 'END{ print $1}`
!define INSTALLSIZE 15327
# Ask for administrative rights
# Other options include:
# none
# user
# highest
RequestExecutionLevel admin
# Default installation location
# let's clutter up our root directory!
InstallDir "C:\${APPSHORTNAME}"
# Text (or RTF) file with license information.
# The text file must be in DOS end line format (\r\n)
LicenseData "LICENSE.md"
#'Name' goes in the installer's title bar
Name "${COMPANYNAME}-${APPSHORTNAME}"
# Icon for the installer - this is the default icon
# The following lines replace the default icons
!include "MUI2.nsh"
#The name of the installer executable
outFile "${APPSHORTNAME}-inst.exe"
#...Not certain about this one
!include LogicLib.nsh
# Defines installation pages
# these are known to NSIS
# Shows the license
Page license
#Allows user to pick install path
Page directory
#Installs the files
Page instfiles
#A macro to verify that administrator rights have been acquired
!macro VerifyUserIsAdmin
UserInfo::GetAccountType
pop $0
${If} $0 != "admin" ;Require admin rights on NT4+
messageBox mb_iconstop "Administrator rights required!"
setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
quit
${EndIf}
!macroend
#This ensures the administrator check is performed at startup?
function .onInit
setShellVarContext all
!insertmacro VerifyUserIsAdmin
functionEnd
# Files for the install directory
# to build the installer,
# these should be in the same directory as the install script (this file)
section "install"
setOutPath $INSTDIR
CreateDirectory $INSTDIR\"maixpy_m5stickv"
# Files added here should be removed by the uninstaller (see section "uninstall")
file "README.md"
file "LICENSE.md"
file "favicon.png"
file "ktool-win.exe"
file "maixpy_m5stickv/firmware.bin"
file "maixpy_m5stickv/kboot.kfpkg"
# Files added here
# should be removed
# by the uninstaller
# (see section "uninstall")
# file /r ..\dist\*.*
# Uninstaller - See function un.onInit and section "uninstall" for configuration
WriteUninstaller "$INSTDIR\uninstall.exe"
#Add a directory for logfiles
#CreateDirectory $INSTDIR\logs
# Start Menu
CreateDirectory "$SMPROGRAMS\${COMPANYNAME}"
#CreateShortcut "$SMPROGRAMS\${COMPANYNAME}\${APPSHORTNAME}.lnk" "$INSTDIR\${APPSHORTNAME}.exe" "" "$INSTDIR\favicon.png"
# Registry information for add/remove programs
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayName" "${COMPANYNAME} - ${APPNAME} - ${DESCRIPTION}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "InstallLocation" "$\"$INSTDIR$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayIcon" "$\"$INSTDIR\favicon.png$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "Publisher" "$\"${COMPANYNAME}$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "HelpLink" "$\"${HELPURL}$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "URLUpdateInfo" "$\"${UPDATEURL}$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "URLInfoAbout" "$\"${ABOUTURL}$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayVersion" "$\"${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}$\""
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "VersionMajor" ${VERSIONMAJOR}
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "VersionMinor" ${VERSIONMINOR}
# There is no option for modifying or repairing the install
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "NoRepair" 1
# Set the INSTALLSIZE constant (!defined at the top of this script) so Add/Remove Programs can accurately report the size
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "EstimatedSize" ${INSTALLSIZE}
sectionEnd
# Uninstaller
function un.onInit
SetShellVarContext all
#Verify the uninstaller - last chance to back out
MessageBox MB_OKCANCEL "Permanantly remove ${APPNAME}?" IDOK next
Abort
next:
!insertmacro VerifyUserIsAdmin
functionEnd
section "uninstall"
# Remove Start Menu launcher
# delete "$SMPROGRAMS\${COMPANYNAME}\${APPSHORTNAME}.lnk"
# Try to remove the Start Menu folder - this will only happen if it is empty
rmDir "$SMPROGRAMS\${COMPANYNAME}"
# Remove files
delete $INSTDIR\README.md
delete $INSTDIR\LICENSE.md
delete $INSTDIR\favicon.png
delete "ktool-win.exe"
delete "maixpy_m5stickv/firmware.bin"
delete "maixpy_m5stickv/kboot.kfpkg"
# Always delete uninstaller as the last action
delete $INSTDIR\uninstall.exe
# Try to remove the install directory - this will only happen if it is empty
rmDir $INSTDIR
# Remove uninstaller information from the registry
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}"
sectionEnd
diff --git a/krux b/krux
index e234962..f0e99b9 100755
--- a/krux
+++ b/krux
@@ -184,4 +184,20 @@ elif [ "$1" == "build-release" ]; then
elif [ "$1" == "clean" ]; then
rm -rf build
docker system prune
+elif [ "$1" == "build-win-installer" ]; then
+ declare $(grep -m 1 version pyproject.toml | sed 's/ *= */=/g' | sed 's/"//g')
+ release_dir="krux-v$version"
+
+ if [ -d "$release_dir" ]; then
+ docker build . \
+ --file Dockerfile.win \
+ --tag krux-win-installer \
+ --build-arg VERSION="$version"
+
+ docker create --name extract-win-installer krux-win-installer
+ docker cp extract-win-installer:/src/krux-inst.exe $release_dir/krux-inst.exe
+ docker rm extract-win-installer
+ else
+ echo "ERROR: directory '$release_dir' not found. Please run './krux build-release' first"
+ fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment