Cleanup some install scripts

This commit is contained in:
doyle 2023-01-30 23:43:54 +11:00
parent 00cd69734a
commit 216a0014e3
5 changed files with 56 additions and 1587 deletions

View File

@ -26,33 +26,6 @@ from enum import Enum
DOWNLOAD_CHUNK_SIZE = 1 * 1024 * 1024 # 1 megabyte DOWNLOAD_CHUNK_SIZE = 1 * 1024 * 1024 # 1 megabyte
IS_WINDOWS = os.name == "nt" IS_WINDOWS = os.name == "nt"
script_dir = os.path.dirname(os.path.abspath(__file__))
default_base_dir = script_dir
default_base_downloads_dir = os.path.join(default_base_dir, 'Downloads')
default_base_install_dir = os.path.join(default_base_dir, 'Install')
# Arguments
# ------------------------------------------------------------------------------
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('--downloads-dir',
help=f'Set the directory where downloaded files are cached (default: {default_base_downloads_dir})',
default=default_base_downloads_dir,
type=pathlib.Path)
arg_parser.add_argument('--install-dir',
help=f'Set the directory where downloaded files are installed (default: {default_base_install_dir})',
default=default_base_install_dir,
type=pathlib.Path)
arg_parser.add_argument('--version',
action='version',
version='DEVenver v1')
args = arg_parser.parse_args()
base_downloads_dir = args.downloads_dir
base_install_dir = args.install_dir
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# This app list must always be installed, they provide the tools to install all # This app list must always be installed, they provide the tools to install all
# other archives. Upon installation, we will collect the installation executable # other archives. Upon installation, we will collect the installation executable
@ -651,6 +624,14 @@ def install_app_list(app_list, download_dir, install_dir):
return result return result
script_dir = os.path.dirname(os.path.abspath(__file__))
default_base_dir = script_dir
default_base_downloads_dir = os.path.join(default_base_dir, 'Downloads')
default_base_install_dir = os.path.join(default_base_dir, 'Install')
base_downloads_dir = default_base_downloads_dir
base_install_dir = default_base_install_dir
def run(user_app_list, def run(user_app_list,
download_dir=base_downloads_dir, download_dir=base_downloads_dir,
install_dir=base_install_dir): install_dir=base_install_dir):
@ -671,6 +652,10 @@ def run(user_app_list,
result (list): A list of dictionaries containing the install locations result (list): A list of dictionaries containing the install locations
of each app, e.g. of each app, e.g.
""" """
base_downloads_dir = download_dir
base_install_dir = install_dir
# Run # Run
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# Create the starting directories and install the internal app list (e.g. # Create the starting directories and install the internal app list (e.g.
@ -730,5 +715,28 @@ def run(user_app_list,
return result return result
if __name__ == '__main__': if __name__ == '__main__':
# Arguments
# ------------------------------------------------------------------------------
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('--downloads-dir',
help=f'Set the directory where downloaded files are cached (default: {default_base_downloads_dir})',
default=default_base_downloads_dir,
type=pathlib.Path)
arg_parser.add_argument('--install-dir',
help=f'Set the directory where downloaded files are installed (default: {default_base_install_dir})',
default=default_base_install_dir,
type=pathlib.Path)
arg_parser.add_argument('--version',
action='version',
version='DEVenver v1')
args = arg_parser.parse_args()
base_downloads_dir = args.base_install_dir
base_install_dir = args.install_dir
run() run()

View File

@ -814,7 +814,7 @@ def get_manifest():
{ {
"download_url": f"https://github.com/WerWolv/ImHex/releases/download/v{version}/imhex-{version}-Windows-Portable.zip", "download_url": f"https://github.com/WerWolv/ImHex/releases/download/v{version}/imhex-{version}-Windows-Portable.zip",
"download_checksum": "4f58097c3ccee88d8dff0d48da0f239af8a9d444903cc19a3369f63caa8d77e6", "download_checksum": "4f58097c3ccee88d8dff0d48da0f239af8a9d444903cc19a3369f63caa8d77e6",
"version": f"version", "version": f"{version}",
"executables": [ "executables": [
{ {
"path": "imhex.exe", "path": "imhex.exe",

View File

@ -1,204 +0,0 @@
@echo off
setlocal EnableDelayedExpansion
REM Win Helpers - Version 11
call %*
goto exit
:DownloadFile
REM call win_helpers.bat :DownloadFile <url> <dest>
REM ------------------------------------------------------------------------------------------------
set url=%~1
set dest_file=%~2
if exist "!dest_file!" (
echo - [DownloadFile/Cached] !url! to !dest_file!
) else (
echo - [DownloadFile] !url! to !dest_file!
call powershell -NoLogo -NoProfile -NonInteractive -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest !url! -OutFile !dest_file! -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::FireFox"
)
if exist "!dest_file!" (
exit /B 0
) else (
echo [DownloadFile] Download failed [url=!url!]
exit /B 1
)
:OverwriteCopy
REM ------------------------------------------------------------------------------------------------
set src_file=%~1
set dest_file=%~2
if not exist "!src_file!" (
echo - [OverwriteCopy] File to copy does not exist [file=%src_file%]
exit /B 1
)
echo - [OverwriteCopy] !src_file! to !dest_file!
call copy /Y !src_file! !dest_file! > nul
exit /B 0
:Unzip
REM call win_helpers.bat :Unzip <path/to/7z.exe> <zip_file> <dest>
REM Overwrite mode: "-aos" Skip extracting of existing files
REM ------------------------------------------------------------------------------------------------
set zip7_exe=%~1
set zip_file=%~2
set dest=%~3
if not exist "!zip7_exe!" (
echo - [Unzip] Failed, 7zip exe not found [path=%zip7_exe%]
exit /B 1
)
if not exist "!zip_file!" (
echo - [Unzip] Failed, zip to unzip does not exist [path=%zip_file%]
exit /B 1
)
echo - [Unzip] !zip_file! to !dest!
call !zip7_dir!\7z.exe x -y -aos -spe -o!dest! !zip_file!
exit /B %ERRORLEVEL%
:FileHashCheck
REM call win_helpers.bat :FileHashCheck [sha256|md5|...] <file> <hash>
REM ------------------------------------------------------------------------------------------------
set algorithm=%~1
set file=%~2
set expected=%~3
if not exist "!file!" (
echo - [FileHashCheck] File does not exist [file=%file%]
exit /B 1
)
REM Calculate hash
for /F %%c in ('powershell -NoLogo -NoProfile -NonInteractive "Get-FileHash -algorithm !algorithm! \"!file!\" | Select-Object -ExpandProperty Hash "') do ( set "actual=%%c" )
REM Verify Hash
if /I "!expected!" neq "!actual!" (
echo - [FileHashCheck] !algorithm! failed [file=!file!,
echo expect=!expected!,
echo actual=!actual!
echo ]
exit /B 1
)
echo - [FileHashCheck] !algorithm! OK [file=!file! hash=!expected!]
exit /B 0
:MoveDir
REM call win_helpers.bat :MoveDir <src> <dest>
REM ------------------------------------------------------------------------------------------------
set src=%~1
set dest=%~2
if not exist "!src!" (
echo - [MoveDir] Directory does not exist [dir=%src%]
exit /B 1
)
echo - [MoveDir] "!src!" to "!dest!"
robocopy "!src!" "!dest!" /E /MOVE /MT /NP /NJS /NS /NC /NFL /NDL
exit /B 0
:MakeBatchShortcut
REM call win_helpers.bat :MakeBatchShortcut <name> <exe> <dest_dir>
REM ------------------------------------------------------------------------------------------------
REM NOTE we make a batch file instead of a symlink because symlinks require
REM admin privileges in windows ...
set name=%~1
set executable=%~2
set dest_dir=%~3
if not exist "!executable!" (
echo - [MakeBatchShortcut] Executable for shortcut does not exist [exe=%executable%]
exit /B 1
)
if not exist "!dest_dir!" (
echo - [MakeBatchShortcut] Shortcut destination directory does not exist [dir=%dest_dir%]
exit /B 1
)
echo - [MakeBatchShortcut] Create [name=!name!, exe=!executable!, dest=!dest_dir!]
echo @echo off> "!dest_dir!\!name!.bat"
echo !executable! %%*>> "!dest_dir!\!name!.bat"
exit /B 0
:MakeRelativeBatchShortcut
REM call win_helpers.bat :MakeRelativeBatchShortcut <name> <exe> <dest_dir>
REM ------------------------------------------------------------------------------------------------
REM NOTE we make a batch file instead of a symlink because symlinks require
REM admin privileges in windows ...
set name=%~1
set executable=%~2
set dest_dir=%~3
if not exist "!dest_dir!\!executable!" (
echo - [MakeRelativeBatchShortcut] Executable for shortcut does not exist [exe=!dest_dir!\%executable%]
exit /B 1
)
if not exist "!dest_dir!" (
echo - [MakeRelativeBatchShortcut] Shortcut destination directory does not exist [dir=%dest_dir%]
exit /B 1
)
echo - [MakeRelativeBatchShortcut] Create [name=!name!, exe=!dest_dir!\!executable!, dest=!dest_dir!]
echo @echo off> "!dest_dir!\!name!.bat"
echo %%~dp0!executable! %%*>> "!dest_dir!\!name!.bat"
exit /B 0
:MakeFileHardLink
REM call win_helpers.bat :MakeFileHardLink dest src
REM ------------------------------------------------------------------------------------------------
set dest=%~1
set src=%~2
if not exist "!src!" (
echo - [MakeFileHardLink] Source file does not exist [src=!src!]
exit /B 1
)
if exist "%dest%" (
del "!dest!"
if exist "!dest!" (
echo - [MakeFileHardLink] Failed to delete destination file [dest=!dest!]
exit /B 1
)
)
mklink /H "!dest!" "!src!"
if not exist "!dest!" (
echo - [MakeFileHardLink] Failed to make hard link at dest [src=!src!, dest=!dest!]
exit /B 1
)
exit /B 0
:MakeDirHardLink
REM call win_helpers.bat :MakeDirHardLink dest src
REM ------------------------------------------------------------------------------------------------
set dest=%~1
set src=%~2
if not exist "!src!" (
echo - [MakeDirHardLink] Source file does not exist [src=!src!]
exit /B 1
)
if exist "%dest%" (
rmdir /S /Q "!dest!"
if exist "!dest!" (
echo - [MakeDirHardLink] Failed to delete destination dir [dest=!dest!]
exit /B 1
)
)
mklink /J "!dest!" "!src!"
if not exist "!dest!" (
echo - [MakeDirHardLink] Failed to make hard link at dest [src=!src!, dest=!dest!]
exit /B 1
)
exit /B 0
:exit
exit /B

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@ import pathlib
import os import os
import shutil import shutil
import tempfile import tempfile
import devenver_manifest import win_devenver_manifest
import urllib.request import urllib.request
def git_clone(install_dir, git_exe, url, commit_hash): def git_clone(install_dir, git_exe, url, commit_hash):
@ -30,8 +30,13 @@ def git_clone(install_dir, git_exe, url, commit_hash):
# Run DEVenver, installing the portable apps # Run DEVenver, installing the portable apps
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
user_app_list = devenver_manifest.get_manifest() download_dir = pathlib.Path(os.path.join(devenver.script_dir, 'Downloads'))
installed_apps = devenver.run(user_app_list) install_dir = pathlib.Path(os.path.join(devenver.script_dir, 'Win'))
user_app_list = win_devenver_manifest.get_manifest()
installed_apps = devenver.run(user_app_list=user_app_list,
download_dir=download_dir,
install_dir=install_dir)
# Install MSVC # Install MSVC
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -40,7 +45,7 @@ msvc_script = pathlib.Path(devenver.script_dir, "win_portable_msvc.py")
msvc_version = "14.34" msvc_version = "14.34"
win10_sdk_version = "22621" win10_sdk_version = "22621"
msvc_install_dir = devenver.base_install_dir / "msvc" msvc_install_dir = install_dir / "msvc"
# Basic heuristic to see if we"ve already installed the MSVC/SDK version # Basic heuristic to see if we"ve already installed the MSVC/SDK version
msvc_installed = False msvc_installed = False
@ -138,7 +143,7 @@ git_clone(install_dir=clink_completions_install_dir,
# Odin # Odin
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
odin_git_hash = "9ae1bfb6" odin_git_hash = "9ae1bfb6"
odin_install_dir = pathlib.Path(devenver.base_install_dir, "Odin") odin_install_dir = pathlib.Path(install_dir, "Odin")
git_clone(install_dir=odin_install_dir, git_clone(install_dir=odin_install_dir,
git_exe=git_exe, git_exe=git_exe,
url="https://github.com/odin-lang/odin.git", url="https://github.com/odin-lang/odin.git",
@ -231,9 +236,9 @@ wezterm_config_dest_path = wezterm_install_dir / "wezterm.lua"
devenver.lprint(f"Installing WezTerm config to {wezterm_config_dest_path}") devenver.lprint(f"Installing WezTerm config to {wezterm_config_dest_path}")
clink_exe_path = clink_install_dir.relative_to(devenver.base_install_dir) / "clink_x64.exe" clink_exe_path = clink_install_dir.relative_to(install_dir) / "clink_x64.exe"
clink_exe_path_for_wezterm = str(clink_exe_path).replace("\\", "\\\\") clink_exe_path_for_wezterm = str(clink_exe_path).replace("\\", "\\\\")
clink_profile_path_for_wezterm = str(clink_profile_dir.relative_to(devenver.base_install_dir)).replace("\\", "\\\\") clink_profile_path_for_wezterm = str(clink_profile_dir.relative_to(install_dir)).replace("\\", "\\\\")
wezterm_lua_buffer = f"""local wezterm = require 'wezterm'; wezterm_lua_buffer = f"""local wezterm = require 'wezterm';
@ -272,8 +277,8 @@ with open(wezterm_config_dest_path, "w") as file:
file.write(wezterm_lua_buffer) file.write(wezterm_lua_buffer)
# Wezterm super terminal # Wezterm super terminal
wezterm_exe_rel_path = pathlib.Path(wezterm_exe_path).relative_to(devenver.base_install_dir) wezterm_exe_rel_path = pathlib.Path(wezterm_exe_path).relative_to(install_dir)
wezterm_terminal_script_path = pathlib.Path(devenver.base_install_dir, "win_terminal.bat") wezterm_terminal_script_path = pathlib.Path(install_dir, "win_terminal.bat")
wezterm_terminal_script = f"""@echo off wezterm_terminal_script = f"""@echo off
setlocal EnableDelayedExpansion setlocal EnableDelayedExpansion
@ -312,8 +317,8 @@ odin_msvc_uninstall_script = f"""Windows Registry Editor Version 5.00
"KitsRoot10"=- "KitsRoot10"=-
""" """
odin_msvc_install_script_path = devenver.base_install_dir / "odin_msvc_install_workaround.reg" odin_msvc_install_script_path = install_dir / "odin_msvc_install_workaround.reg"
odin_msvc_uninstall_script_path = devenver.base_install_dir / "odin_msvc_uninstall_workaround.reg" odin_msvc_uninstall_script_path = install_dir / "odin_msvc_uninstall_workaround.reg"
devenver.lprint(f"Installing Odin MSVC workaround scripts", level=0) devenver.lprint(f"Installing Odin MSVC workaround scripts", level=0)
devenver.lprint(f" - {odin_msvc_install_script_path}", level=1) devenver.lprint(f" - {odin_msvc_install_script_path}", level=1)
@ -330,9 +335,9 @@ with open(odin_msvc_uninstall_script_path, "w") as file:
# TODO: If I'm using the terminal that this script generates it will lock the # TODO: If I'm using the terminal that this script generates it will lock the
# executable and Python cannot open the file for verifying the SHA256. # executable and Python cannot open the file for verifying the SHA256.
python_exe = pathlib.Path(installed_apps["Python"][0]['exe_path']).relative_to(devenver.base_install_dir) python_exe = pathlib.Path(installed_apps["Python"][0]['exe_path']).relative_to(install_dir)
python_install_dir = pathlib.Path(installed_apps["Python"][0]['exe_path']).parent.relative_to(devenver.base_install_dir) python_install_dir = pathlib.Path(installed_apps["Python"][0]['exe_path']).parent.relative_to(install_dir)
win_setup_script_path = pathlib.Path(devenver.script_dir, "win_setup.py") win_setup_script_path = pathlib.Path(devenver.script_dir, "win_install.py")
bootstrap_setup_script = f"""@echo off bootstrap_setup_script = f"""@echo off
setlocal EnableDelayedExpansion setlocal EnableDelayedExpansion
@ -341,5 +346,5 @@ set PYTHONHOME=%~dp0{python_install_dir}
pause pause
""" """
with open(devenver.base_install_dir / "upgrade_bootstrap.bat", "w") as file: with open(install_dir / "upgrade_bootstrap.bat", "w") as file:
file.write(bootstrap_setup_script) file.write(bootstrap_setup_script)