Skip to content

Commit

Permalink
Installer (#1)
Browse files Browse the repository at this point in the history
* Add gitignore

* WIP: MSYS2 installer

* Tweaks

* .appveyor.yml: add artifacts

* .appveyor.yml: add quotes around commands

* .appveyor.yml: try to mitigate against MSYS signature problem

error: mingw64: signature from "David Macek <[email protected]>" is unknown trust
error: failed to update mingw64 (invalid or corrupted database (PGP signature))

* .appveyor.yml: try to update to VS2019 image to get more recent MSYS

See https://help.appveyor.com/discussions/problems/28154-please-update-msys2

* .appveyor.yml: try to kill all MSYS processes before rebase

* MSYS: install rsync

* Add missing dependency msys-expat-1.dll

Got a generic error when ansible was trying to import pyexpat.
strace'ing python showed that python was able to pick up
pyexpat.cpython-38-x86_64-msys.dll from /usr/lib/python3.8/lib-dynload,
however the DLL failed to load.

Using dumpbin to find the dependencies revealed this:

dumpbin /dependents pyexpat.cpython-38-x86_64-msys.dll
Microsoft (R) COFF/PE Dumper Version 14.28.29335.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file pyexpat.cpython-38-x86_64-msys.dll

File Type: DLL

  Image has the following dependencies:

    msys-python3.8.dll
    msys-expat-1.dll
    msys-2.0.dll
    KERNEL32.dll

  Summary

        1000 .bss
        1000 .buildid
        2000 .data
        1000 .edata
        2000 .idata
        1000 .pdata
        2000 .rdata
        1000 .reloc
        7000 .text
        1000 .xdata

* Add another missing dependency: msys-ffi-7.dll

* Tweaks

* Turn off verbose output for rsync

* AppVeyor: try to fix quote escaping for pywinrm install

* AppVeyor: try to fix quote escaping for pywinrm install

* AppVeyor: try to fix quote escaping for pywinrm install

* Fixes to release.sh

* More tweaks

* Change from bat script to ps script (run as admin)

* Try to setup WinRM

* Remove 'Press any key to continue' prompt from run.sh, since we have it in run.ps1
  • Loading branch information
egraff authored Dec 16, 2020
1 parent a7280a3 commit b7eed22
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
clone_depth: 10

# Needs this for most recent MSYS
image: Visual Studio 2019

environment:
global:
MSYS2_DIR: C:\msys64
MSYS2_ASH: C:\msys64\usr\bin\ash.exe
MSYS2_BASH: C:\msys64\usr\bin\bash.exe

cache:
- '%MSYS2_DIR%\var\cache\pacman'

install:
- '%MSYS2_BASH% --login -c "pacman -Syu --noconfirm"'
- '%MSYS2_BASH% --login -c "pacman -S --noconfirm --needed base-devel msys2-devel gcc"'
- '%MSYS2_BASH% --login -c "pacman -S --noconfirm --needed python3 python3-pip"'
- '%MSYS2_BASH% --login -c "pacman -S --noconfirm --needed libffi libffi-devel"'
- '%MSYS2_BASH% --login -c "pacman -S --noconfirm --needed openssl openssl-devel libcrypt libcrypt-devel"'
- '%MSYS2_BASH% --login -c "pacman -S --noconfirm --needed libyaml-devel"'
- '%MSYS2_BASH% --login -c "pacman -S --noconfirm --needed git openssh rsync tar"'
- '%MSYS2_BASH% --login -c "pacman -S --noconfirm --needed p7zip"'

- ps: Get-Process | Where-Object { $_.Path -like "${env:MSYS2_DIR}*" } | Stop-Process
- '%MSYS2_ASH% -c "/usr/bin/rebaseall -v"'

- '%MSYS2_BASH% --login -c "python3 -mpip install ''pywinrm>=0.3.0''"'
- '%MSYS2_BASH% --login -c "python3 -mpip install ansible"'

- ps: Get-Process | Where-Object { $_.Path -like "${env:MSYS2_DIR}*" } | Stop-Process
- '%MSYS2_ASH% -c "/usr/bin/rebaseall -v"'

- '%MSYS2_BASH% --login -c "curl -L -o 7zsd_extra_170_3900.7z https://github.com/chrislake/7zsfxmm/releases/download/1.7.0.3900/7zsd_extra_170_3900.7z"'
- '%MSYS2_BASH% --login -c "TARGET_DIR=`cd $APPVEYOR_BUILD_FOLDER && pwd` && mkdir $TARGET_DIR/7zsd_extra && 7z e 7zsd_extra_170_3900.7z -o$TARGET_DIR/7zsd_extra"'

build_script:
- '%MSYS2_BASH% --login -c "cd $APPVEYOR_BUILD_FOLDER && ./release.sh"'

artifacts:
- path: winconfig-install.exe
name: installer
type: file

# https://www.appveyor.com/docs/how-to/rdp-to-build-worker/
on_failure:
- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
7zsd_extra/
winconfig-install/
7zsd_extra_170_3900.7z
run.bat
winconfig-install.exe
Empty file added fileList-mingw.txt
Empty file.
83 changes: 83 additions & 0 deletions fileList.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
usr/bin/ansible
usr/bin/ansible-config
usr/bin/ansible-connection
usr/bin/ansible-console
usr/bin/ansible-doc
usr/bin/ansible-galaxy
usr/bin/ansible-inventory
usr/bin/ansible-playbook
usr/bin/ansible-pull
usr/bin/ansible-test
usr/bin/ansible-vault
usr/bin/basename.exe
usr/bin/cat.exe
usr/bin/cp.exe
usr/bin/curl.exe
usr/bin/cygpath.exe
usr/bin/dirname.exe
usr/bin/expr.exe
usr/bin/find.exe
usr/bin/git.exe
usr/bin/grep.exe
usr/bin/hostname.exe
usr/bin/ln.exe
usr/bin/locale.exe
usr/bin/make.exe
usr/bin/mkdir.exe
usr/bin/msys-2.0.dll
usr/bin/msys-asn1-8.dll
usr/bin/msys-brotlicommon-1.dll
usr/bin/msys-brotlidec-1.dll
usr/bin/msys-com_err-1.dll
usr/bin/msys-crypt-0.dll
usr/bin/msys-crypto-1.1.dll
usr/bin/msys-curl-4.dll
usr/bin/msys-expat-1.dll
usr/bin/msys-ffi-7.dll
usr/bin/msys-gcc_s-seh-1.dll
usr/bin/msys-gssapi-3.dll
usr/bin/msys-hcrypto-4.dll
usr/bin/msys-heimbase-1.dll
usr/bin/msys-heimntlm-0.dll
usr/bin/msys-hx509-5.dll
usr/bin/msys-iconv-2.dll
usr/bin/msys-idn2-0.dll
usr/bin/msys-intl-8.dll
usr/bin/msys-krb5-26.dll
usr/bin/msys-nghttp2-14.dll
usr/bin/msys-pcre2-8-0.dll
usr/bin/msys-psl-5.dll
usr/bin/msys-python3.8.dll
usr/bin/msys-roken-18.dll
usr/bin/msys-sqlite3-0.dll
usr/bin/msys-ssh2-1.dll
usr/bin/msys-ssl-1.1.dll
usr/bin/msys-stdc++-6.dll
usr/bin/msys-unistring-2.dll
usr/bin/msys-wind-0.dll
usr/bin/msys-z.dll
usr/bin/mv.exe
usr/bin/perl.exe
usr/bin/python.exe
usr/bin/python3.8.exe
usr/bin/python3.8-config
usr/bin/python3.exe
usr/bin/python3-config
usr/bin/python-config
usr/bin/rm.exe
usr/bin/sed.exe
usr/bin/sh.exe
usr/bin/sort.exe
usr/bin/tzset.exe
usr/bin/uname.exe
usr/bin/which.exe
usr/lib/git-core/git-index-pack.exe
usr/lib/git-core/git-parse-remote
usr/lib/git-core/git-sh-i18n
usr/lib/git-core/git-sh-i18n--envsubst.exe
usr/lib/git-core/git-sh-setup
usr/lib/git-core/git-submodule
usr/lib/git-core/git-remote-http.exe
usr/lib/git-core/git-remote-https.exe
usr/lib/python3.8
usr/share/git-core/templates/description
3 changes: 3 additions & 0 deletions gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[core]
symlinks = false
autocrlf = input
91 changes: 91 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash
set -e

# Note: this script is based on the installer script from msysGit
# (/share/msysGit/net/release.sh)

INSTALLER_NAME="winconfig"
INSTALLER_TITLE="winconfig installation"

TARGET="$(pwd -L)"/${INSTALLER_NAME}-install.exe
TMPDIR=/tmp/msys-rootfs-tmp
OPTS7="-m0=lzma -mx=9 -md=64M"
TMPPACK=/tmp.7z

# Get script dir
cd "$(dirname "${0}")"
SHARE="$(pwd -L)"
cd - > /dev/null

test ! -d "$TMPDIR" || rm -rf "$TMPDIR" || exit
mkdir "$TMPDIR"
cd "$TMPDIR"

(cd .. && test ! -f "$TMPPACK" || rm "$TMPPACK")

echo "Copying files"

mkdir msys64

sed 's/\r//g' "$SHARE"/fileList.txt | while read -r filepath || [ -n "$filepath" ]
do
# do something with $filepath here
rsync --archive --relative --exclude "*.pyc" --exclude "*/__pycache__" --exclude "*/python3.8/**/test*/" /./${filepath} msys64/
done

sed 's/\r//g' "$SHARE"/fileList-mingw.txt | while read -r filepath || [ -n "$filepath" ]
do
# do something with $filepath here
rsync --archive --relative --exclude "*.pyc" --exclude "*/__pycache__" --exclude "*/python3.8/**/test*/" /mingw64/./${filepath} msys64/
done

pushd msys64

strip usr/bin/*.exe usr/lib/git-core/*.exe

mkdir -p usr/share
cp -R /usr/share/terminfo ./usr/share/terminfo

mkdir -p usr/ssl
cp -R /usr/ssl/certs ./usr/ssl/certs

mkdir tmp

mkdir etc
cp "$SHARE"/gitconfig etc/
cp /etc/fstab ./etc/fstab
cp /etc/msystem ./etc/msystem
cp /etc/profile ./etc/profile

mkdir -p dev/shm

if test -d /etc/profile.d
then
cp -R /etc/profile.d ./etc/profile.d
fi

cp "$SHARE"/run.sh run.sh

# Pop msys64 dir, to get back to $TMPDIR
popd

cp "$SHARE"/run.ps1 run.ps1
rsync --archive -v "$SHARE"/ansible/ ansible/

echo "Creating archive"

cd ..
/usr/bin/7za a $OPTS7 "$TMPPACK" msys-rootfs-tmp
(cat "$SHARE"/7zsd_extra/7zsd_All_x64.sfx &&
echo ';!@Install@!UTF-8!' &&
echo "Title=\"${INSTALLER_TITLE}\"" &&
echo 'GUIFlags="8+32+64+256+4096"' &&
echo 'GUIMode="1"' &&
echo 'OverwriteMode="2"' &&
echo "RunProgram=\"powershell.exe -WindowStyle Hidden -Command Start-Process -Wait -Verb RunAs powershell.exe -ArgumentList '-ExecutionPolicy ByPass -File \\\"%%T\\msys-rootfs-tmp\\run.ps1\\\"'\"" &&
echo ';!@InstallEnd@!' &&
cat "$TMPPACK") > "$TARGET"

echo "Success! You'll find the new installer at \"$TARGET\"."
rm $TMPPACK
rm -rf "$TMPDIR"
32 changes: 32 additions & 0 deletions run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
try
{
cd $PSScriptRoot

Enable-PSRemoting -SkipNetworkProfileCheck
if ((Get-WSManInstance -ResourceURI winrm/config/service/auth).Negotiate -ne 'true')
{
Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WSMAN\Service -Name auth_negotiate -Value 1 -Type DWord
Restart-Service WinRM
}

$shouldResetUac = $false
$uacProperty = Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System | Select-Object -ExpandProperty LocalAccountTokenFilterPolicy
if ($uacProperty -ne 1)
{
$shouldResetUac = $true
Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name LocalAccountTokenFilterPolicy -Value 1 -Type DWord
}

cd ansible
& ..\msys64\usr\bin\sh.exe /run.sh
}
finally
{
if ($shouldResetUac)
{
Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name LocalAccountTokenFilterPolicy -Value 0 -Type DWord
}

Write-Host -NoNewLine 'Press any key to continue...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}
24 changes: 24 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

# Note: this script is based on the setup script from msysGit
# (/share/msysGit/net/setup-msysgit.sh)

ORIG_PATH=$PATH
export PATH="/usr/local/bin:/usr/bin:/bin:/opt/bin:$PATH"

error () {
echo "* error: $*"
echo INSTALLATION ABORTED
read -e IGNORED_INPUT
trap - exit
exit 1
}

echo
echo "-------------------------------------------------------"
echo "Running Ansible (will prompt for username and password)"
echo "-------------------------------------------------------"

ansible-playbook site.yml -v

echo "DONE!"

0 comments on commit b7eed22

Please sign in to comment.