Browse Source

1st attempt at installing greenhouse-background-service on windows

master
forest 2 months ago
parent
commit
bcf45bb2d0
6 changed files with 114 additions and 21 deletions
  1. +2
    -1
      .gitignore
  2. +16
    -4
      README.md
  3. +64
    -15
      src/installer/windows/Installer.nsi
  4. +31
    -0
      src/installer/windows/get-background-service-installer-files.sh
  5. BIN
      src/installer/windows/secure-random.exe
  6. +1
    -1
      src/installer/windows/secure-random.go

+ 2
- 1
.gitignore View File

@ -5,4 +5,5 @@ __pycache__
*.kra
target/
my_dist/
my_dist/
src/installer/windows/background-service

+ 16
- 4
README.md View File

@ -61,14 +61,16 @@ chown 1000:1000 my_dist/greenhouse-desktop.deb
### building a release on Windows
* `GOOS=windows go build -o src/installer/windows/secure-random.exe src/installer/windows/secure-random.go`
* build the secure-random.exe if its not already built
* `GOOS=windows go build -o src/installer/windows/secure-random.exe src/installer/windows/secure-random.go`
* [create a windows virtual machine](https://dennisnotes.com/note/20180614-ubuntu-18.04-qemu-setup/)
* [get python 3.8.6](https://www.python.org/downloads/release/python-368/)
* install the [Microsoft Visual C++ 2010 Service Pack 1 Redistributable Package MFC Security Update ](https://www.microsoft.com/en-us/download/details.aspx?id=26999)
* install the [Visual C++ Redistributable for Visual Studio 2012](https://www.microsoft.com/en-us/download/details.aspx?id=30679)
* install the [Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019](https://aka.ms/vs/16/release/vc_redist.x64.exe)
* install [visual studio 2019](https://visualstudio.microsoft.com/downloads/) (Choose "Desktop development with C++" (not sure if this is needed???))
<!-- * install [visual studio 2019](https://visualstudio.microsoft.com/downloads/) (Choose "Desktop development with C++" (not sure if this is needed???)) -->
* open file explorer and search `C:\` for `api-ms-win-crt-multibyte-l1-1-0.dll`
* Start Menu > search for "Edit the System Environment Variables"
- Environment Variables... > System Variables > Path > Edit...
@ -77,8 +79,8 @@ chown 1000:1000 my_dist/greenhouse-desktop.deb
* install [Nullsoft Scriptable Install System (NSIS)](https://nsis.sourceforge.io/Download)
* download the [NSIS Simple Service Plugin](https://nsis.sourceforge.io/NSIS_Simple_Service_Plugin)
* copy `SimpleSC.dll` into `C:\Program Files (x86)\NSIS\Plugins\x86-unicode`
* download the [NSIS Pwgen Plugin](https://nsis.sourceforge.io/Pwgen_plug-in)
* copy `pwgen.dll` into `C:\Program Files (x86)\NSIS\Plugins\x86-unicode`
* download the [NSIS User Manager Plugin](https://nsis.sourceforge.io/UserMgr_plug-in)
* copy `UserMgr.dll` into `C:\Program Files (x86)\NSIS\Plugins\x86-unicode`
* Start Menu > search for "Edit the System Environment Variables"
- Environment Variables... > System Variables > Path > Edit...
- Choose "New" and enter `C:\Users\venie\AppData\Local\Programs\Python\Python36`
@ -87,6 +89,16 @@ chown 1000:1000 my_dist/greenhouse-desktop.deb
* install [git for windows](https://git-scm.com/download/windows)
* `git clone https://git.sequentialread.com/forest/greenhouse-desktop.git`
* `cd greenhouse-desktop`
* download / set up the greenhouse-background-service files if its not done already
* `cd src/installer/windows`
* `./get-background-service-installer-files.sh`
<!-- * this script will:
* make the `src/installer/windows/background-service` folder (this folder is gitignored)
* download/place the required greenhouse-daemon installation files into it:
* `greenhouse-background-service.exe` (greenhouse-daemon)
* `greenhouse-threshold.exe`
* `greenhouse-caddy.exe`
* `caddy-config.json` -->
* enter the windows cmd.exe shell instead of git bash
* `python --version`
* `python -m venv venv`


+ 64
- 15
src/installer/windows/Installer.nsi View File

@ -86,32 +86,81 @@ FunctionEnd
"Software\Microsoft\Windows\CurrentVersion\Uninstall\${app_name}"
Section
; First we have to install secure-random.exe
; So that we can generate a secure password for the user we will create for the windows service.
SetOutPath "$InstDir"
File "..\installer\secure-random.exe"
File "secure-random.exe"
Var /GLOBAL GREENHOUSE_SERVICE_USER_PASSWORD
Var /GLOBAL MY_ERROR_MSG
nsExec::ExecToStack "$InstDir\secure-random.exe"
Pop $0
Pop $1
MessageBox MB_OK "New random password: $0 $1"
; https://nsis.sourceforge.io/Pwgen_plug-in
Var /GLOBAL GREENHOUSE_DAEMON_USER_PASSWORD
pwgen::GeneratePassword 32
Pop $0
IntFmt $0 "0x%032X" $0
MessageBox MB_OK "New random password: $0"
StrCpy $GREENHOUSE_DAEMON_USER_PASSWORD "asd: $0"
MessageBox MB_OK "New random password2: $GREENHOUSE_DAEMON_USER_PASSWORD"
${If} "$0" == "0"
StrCpy $GREENHOUSE_SERVICE_USER_PASSWORD "$1"
DetailPrint "Generated a secure random password for the greenhouse-background-service user"
${Else}
DetailPrint "$InstDir\secure-random.exe returned exit code $0. Aborting"
MessageBox MB_OK "$InstDir\secure-random.exe returned exit code $0. Aborting"
Abort
${EndIf}
MessageBox MB_OK "New random password2: $GREENHOUSE_SERVICE_USER_PASSWORD"
; https://nsis.sourceforge.io/UserMgr_plug-in#Example
UserMgr::CreateAccountEx "greenhouse-test" "$GREENHOUSE_DAEMON_USER_PASSWORD" "greenhouse service user" "" "greenhouse service user" "UF_DONT_EXPIRE_PASSWD"
UserMgr::CreateAccountEx "greenhouse-background-service" "$GREENHOUSE_SERVICE_USER_PASSWORD" "greenhouse background service user" "" "greenhouse background service user" "UF_DONT_EXPIRE_PASSWD|UF_PASSWD_CANT_CHANGE"
Pop $0
MessageBox MB_OK "CreateUserEx Result : $0"
${If} "$0" == "OK"
DetailPrint "Created the greenhouse-background-service user"
${Else}
StrCpy $MY_ERROR_MSG "Attempting to create the greenhouse-background-service user returned error code $0. Aborting. $\r$\n\$\r$\n\
For more information, see https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--1300-1699- $\r$\n\
or $\r$\n\
https://docs.microsoft.com/en-us/windows/win32/netmgmt/network-management-error-codes $\r$\n"
DetailPrint "$MY_ERROR_MSG"
MessageBox MB_OK "$MY_ERROR_MSG"
Abort
${EndIf}
; 544 means the user is a local admin.
UserMgr::AddToGroup "greenhouse-test" "[S-1-5-32-544]"
UserMgr::AddToGroup "greenhouse-background-service" "[S-1-5-32-544]"
Pop $0
MessageBox MB_OK "AddToGroup Result : $0"
${If} "$0" == "OK"
DetailPrint "Made greenhouse-background-service user a Local Admin"
${Else}
StrCpy $MY_ERROR_MSG "Attempting to make the greenhouse-background-service user a Local Admin returned error code $0. Aborting. $\r$\n\$\r$\n\
For more information, see https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--1300-1699- $\r$\n\
or $\r$\n\
https://docs.microsoft.com/en-us/windows/win32/netmgmt/network-management-error-codes $\r$\n"
DetailPrint "$MY_ERROR_MSG"
MessageBox MB_OK "$MY_ERROR_MSG"
Abort
${EndIf}
; Now we install the greenhouse background service (greenhouse-daemon)
SetOutPath "$InstDir\background-service"
File /r "background-service\*"
; See https://nsis.sourceforge.io/NSIS_Simple_Service_Plugin
; SimpleSC::InstallService [name_of_service] [display_name] [service_type] [start_type] [binary_path] [dependencies] [account] [password]
; service_type 16 - SERVICE_WIN32_OWN_PROCESS
; start_type 2 - SERVICE_AUTO_START
SimpleSC::InstallService "GreenhouseBackgroundService" "Greenhouse Background Service" "16" "2" "$InstDir\background-service\greenhouse-background-service.exe" "" "greenhouse-background-service" "$GREENHOUSE_SERVICE_USER_PASSWORD"
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
${If} "$0" == "0"
DetailPrint "Installed the greenhouse-background-service windows service"
${Else}
StrCpy $MY_ERROR_MSG "Attempting to install the greenhouse-background-service windows service returned error code $0. Aborting. $\r$\n\$\r$\n\
For more information, see https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--1300-1699- $\r$\n\
or $\r$\n\
https://docs.microsoft.com/en-us/windows/win32/netmgmt/network-management-error-codes $\r$\n"
DetailPrint "$MY_ERROR_MSG"
MessageBox MB_OK "$MY_ERROR_MSG"
Abort
${EndIf}
SetOutPath "$InstDir"
File /r "..\${app_name}\*"


+ 31
- 0
src/installer/windows/get-background-service-installer-files.sh View File

@ -0,0 +1,31 @@
#!/bin/bash
curl --silent --show-error --output "caddy.gz" \
"https://picopublish.sequentialread.com/files/caddy-v2.4.0-beta.2-forest-078f12e0-f2a3-windows-amd64.gz"
curl --silent --show-error --output "greenhouse-background-service.gz" \
"https://picopublish.sequentialread.com/files/greenhouse-daemon-0.0.0-91dca98-f418-windows-amd64.gz"
curl --silent --show-error --output "threshold.gz" \
"https://picopublish.sequentialread.com/files/threshold-0.0.0-6cfcabd-5a08-windows-amd64.gz"
mkdir -p background-service
gzip --stdout --decompress "caddy.gz" > "background-service/greenhouse-caddy.exe"
gzip --stdout --decompress "greenhouse-background-service.gz" > "background-service/greenhouse-background-service.exe"
gzip --stdout --decompress "threshold.gz" > "background-service/greenhouse-threshold.exe"
printf '
{
"admin": {
"disabled": false,
"listen": "127.0.0.1:9574",
"authorized_clients_ca_file": "greenhouse_daemon_localhost_ca.crt",
"tls_key_file": "greenhouse-daemon.key",
"tls_cert_file": "greenhouse-daemon.crt",
"config": {
"persist": false
}
}
}
' > background-service/caddy-config.json

BIN
src/installer/windows/secure-random.exe View File


+ 1
- 1
src/installer/windows/secure-random.go View File

@ -12,5 +12,5 @@ func main() {
if n != 16 || err != nil {
os.Exit(1)
}
fmt.Printf("%x\n", buffer)
fmt.Printf("%x", buffer)
}

Loading…
Cancel
Save