Skip to content

Commit

Permalink
Use GitHub actions to deploy pages
Browse files Browse the repository at this point in the history
  • Loading branch information
OBarronCS committed Oct 6, 2024
1 parent 3d63ab0 commit 70dc46c
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/pages-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Deploy to GitHub Pages

on:
workflow_dispatch:
push:
branches: [main]


jobs:
upload:
runs-on: ubuntu-latest
steps:
- name: Setup Pages
uses: actions/[email protected]

- name: Checkout
uses: actions/[email protected]

- name: Choose files to deploy
mkdir public
mv wsl.ps1 public

- name: Upload GitHub Pages Artifact
uses: actions/[email protected]
with:
path: public

deploy:
permissions:
contents: read
pages: write
id-token: write

needs: upload
runs-on: ubuntu-latest

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/[email protected]
68 changes: 68 additions & 0 deletions wsl.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

function Get-DistroName {
param (
[string]$base_name
)
$counter = 1
$unique_name = $base_name
$all_distros = wsl -l -q

while ($all_distros -contains $unique_name) {
$unique_name = "$base_name-$counter"
$counter++
}

return $unique_name
}

$base_name = "pwnbox"
$distro_name = Get-DistroName -base_name $base_name

$timestamp = (Get-Date).ToString("yyyyMMddHHmmss")
$out_file_name = "wsl_rootfs_$timestamp.tar.gz"

Write-Output "Downloading the latest release file for the WSL root filesystem"
Import-Module BitsTransfer

$json_api_data = (irm api.github.com/repos/obarroncs/pwnbox/releases/latest | % assets)[0]
$download_url = $json_api_data.browser_download_url
$file_size = $json_api_data.size

$file_size_gb = [math]::round($file_size / 1Gb,4)

Write-Output "The file is ${file_size_gb}GB - writing to $pwd\$out_file_name"

Write-Output "Starting file download: $download_url"
$download_attempt = Start-BitsTransfer $download_url -Destination $out_file_name

if (-not $?){
Write-Output "Failed to download the pre-built root filesystem"
exit 1
}

# # Validate that the size lines up
# $downloaded_file_size = (Get-Item $out_file_name).Length

# if ($value1 -ne $value2) {
# Write-Output "Download failed - the downloaded file size does not line up with the expected size"
# exit 1
# }

Write-Output "Creating a WSL distro with file: $out_file_name"
Write-Output "Running the following command:"
Write-Output ""
Write-Output "wsl --import $distro_name "$HOME/wsl_managed_pwnbox_timestamp" $out_file_name 2>&1"
Write-Output ""
Write-Output "This may take a moment"
wsl --import $distro_name "$HOME/wsl_managed_pwnbox_$timestamp" $out_file_name 2>&1

if ($?) {
Write-Output "Successfully installed pwnbox"
Write-Output "Name: $distro_name"
Write-Output "Use it by running the command: 'wsl -d $distro_name'"
Write-Output "It's also been added to your Windows Terminal profile - restart the Terminal to see it"
} else {
Write-Output "Import failed: $output"
}


0 comments on commit 70dc46c

Please sign in to comment.