Add caddy for Windows 10
authorNorbertLuszkiewicz <norbertluszkiewicz00@gmail.com>
Mon, 31 Aug 2020 07:36:49 +0000 (09:36 +0200)
committerAJ ONeal <aj@therootcompany.com>
Sat, 12 Sep 2020 03:38:39 +0000 (03:38 +0000)
caddy/install.ps1 [new file with mode: 0644]

diff --git a/caddy/install.ps1 b/caddy/install.ps1
new file mode 100644 (file)
index 0000000..cb95876
--- /dev/null
@@ -0,0 +1,56 @@
+#!/usr/bin/env pwsh
+
+#################
+# Install caddy #
+#################
+
+# Every package should define these variables
+$pkg_cmd_name = "caddy"
+
+$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\caddy.exe"
+$pkg_dst = "$pkg_dst_cmd"
+
+$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\caddy-v$Env:WEBI_VERSION\bin\caddy.exe"
+$pkg_src_bin = "$Env:USERPROFILE\.local\opt\caddy-v$Env:WEBI_VERSION\bin"
+$pkg_src_dir = "$Env:USERPROFILE\.local\opt\caddy-v$Env:WEBI_VERSION"
+$pkg_src = "$pkg_src_cmd"
+
+$pkg_download = "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
+
+# Fetch archive
+IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE")) {
+    # TODO: arch detection
+    echo "Downloading caddy from $Env:WEBI_PKG_URL to $pkg_download"
+    & curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part"
+    & move "$pkg_download.part" "$pkg_download"
+}
+
+IF (!(Test-Path -Path "$pkg_src_cmd")) {
+    echo "Installing caddy"
+
+    # TODO: create package-specific temp directory
+    # Enter tmp
+    pushd .local\tmp
+
+    # Remove any leftover tmp cruft 
+    Remove-Item -Path ".\caddy-v*" -Recurse -ErrorAction Ignore
+    Remove-Item -Path ".\caddy.exe" -Recurse -ErrorAction Ignore
+
+    # Unpack archive file into this temporary directory
+    # Windows BSD-tar handles zip. Imagine that.
+    echo "Unpacking $pkg_download"
+    & tar xf "$pkg_download"
+    & dir
+
+    # Settle unpacked archive into place
+    echo "Install Location: $pkg_src_cmd"
+    New-Item "$pkg_src_bin" -ItemType Directory
+    Move-Item -Path ".\caddy-*\caddy.exe" -Destination "$pkg_src_bin"
+
+    # Exit tmp
+    popd
+}
+
+echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'"
+Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore
+Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse