Skip to content

Commit c418b44

Browse files
authored
No pre-reqs (#270)
Windows installer installs without admin privs
1 parent f3f15f7 commit c418b44

File tree

8 files changed

+213
-104
lines changed

8 files changed

+213
-104
lines changed

.github/workflows/ci.action.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,32 @@ jobs:
9494
- run: git clean -xfd
9595
- uses: ./
9696
- run: pkgx --version
97+
- uses: actions/upload-artifact@v4
98+
with:
99+
path: |
100+
./action.js
101+
./action.yml
102+
name: action
103+
104+
linuxen:
105+
needs: dist
106+
continue-on-error: true
107+
runs-on: ubuntu-latest
108+
strategy:
109+
matrix:
110+
container:
111+
- debian:buster-slim
112+
- debian:bullseye-slim
113+
- debian:bookworm-slim
114+
- archlinux:latest
115+
- ubuntu:focal
116+
- ubuntu:jammy
117+
- ubuntu:noble
118+
- fedora:latest
119+
container: ${{ matrix.container }}
120+
steps:
121+
- uses: actions/download-artifact@v4
122+
with:
123+
name: action
124+
- uses: ./
125+
- run: pkgx node -e 'console.log(1)'

.github/workflows/ci.installer.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,15 @@ jobs:
180180
env:
181181
PATH: ${{ github.workspace }}/bin:/usr/bin:/bin
182182

183-
- run: pkgx deno eval 'console.log(1)'
183+
- run: pkgx node -e 'console.log(1)'
184184

185185
windows:
186186
runs-on: windows-latest
187187
steps:
188188
- uses: actions/checkout@v4
189189
- run: .\\installer.ps1
190190
- run: |
191-
$env:Path += ";C:\Program Files\pkgx"
191+
$env:Path += ";$env:LOCALAPPDATA\pkgx"
192192
pkgx +zlib.net
193193
194194
upgrades:

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,16 @@ just slow things down.
4343

4444
## Version History
4545

46+
* `v4` defaults to `pkgx`^2, uses node^20 and doesn’t install any pre-reqs on Linux†
4647
* `v3` defaults to `pkgx`^2 and uses node^20
4748
* `v2` defaults to `pkgx`^1 and uses node^20
4849
* `v1` defaults to `pkgx`@latest and uses node^16
4950
* `v0` should not be used
5051

52+
> † `pkgx` requires glibc>=2.28, libgcc, libstdc++ and libatomic. Generally
53+
> images come installed with these. If you are building binaries you may need
54+
> the `-dev` versions of these packages also.
55+
5156
 
5257

5358

action.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { execSync } = require('child_process');
2+
const unzipper = require('unzipper');
23
const semver = require('semver');
34
const https = require('https');
45
const path = require('path');
@@ -27,23 +28,31 @@ function platform_key() {
2728
}
2829

2930
function downloadAndExtract(url, destination, strip) {
31+
3032
return new Promise((resolve, reject) => {
3133
https.get(url, (response) => {
3234
if (response.statusCode !== 200) {
3335
reject(new Error(`Failed to get '${url}' (${response.statusCode})`));
3436
return;
3537
}
3638

37-
console.log(`extracting tarball…`);
38-
39-
const tar_stream = tar.x({ cwd: destination, strip });
39+
console.log(`extracting pkgx archive…`);
4040

41-
response
42-
.pipe(tar_stream) // Extract directly to destination
43-
.on('finish', resolve)
44-
.on('error', reject);
45-
46-
tar_stream.on('error', reject);
41+
if (platform_key().startsWith('windows')) {
42+
const unzip_stream = unzipper.Extract({ path: destination });
43+
response
44+
.pipe(unzip_stream)
45+
.promise()
46+
.then(resolve, reject);
47+
unzip_stream.on('error', reject);
48+
} else {
49+
const tar_stream = tar.x({ cwd: destination, strip });
50+
response
51+
.pipe(tar_stream)
52+
.on('finish', resolve)
53+
.on('error', reject);
54+
tar_stream.on('error', reject);
55+
}
4756

4857
}).on('error', reject);
4958
});
@@ -93,7 +102,7 @@ async function install_pkgx() {
93102
if (platform_key().startsWith('windows')) {
94103
// not yet versioned
95104
strip = 0;
96-
return 'https://pkgx.sh/Windows/x86_64.tgz';
105+
return 'https://pkgx.sh/Windows/x86_64.zip';
97106
}
98107

99108
let url = `https://dist.pkgx.dev/pkgx.sh/${platform_key()}/versions.txt`;
@@ -139,13 +148,6 @@ async function install_pkgx() {
139148
fs.appendFileSync(process.env["GITHUB_ENV"], `PKGX_DIR=${process.env.INPUT_PKGX_DIR}\n`);
140149
}
141150

142-
if (os.platform() == 'linux') {
143-
console.log(`::group::installing pre-requisites`);
144-
const installer_script_path = path.join(path.dirname(__filename), "installer.sh");
145-
execSync(installer_script_path, {env: {PKGX_INSTALL_PREREQS: '1', ...process.env}});
146-
console.log(`::endgroup::`);
147-
}
148-
149151
if (process.env['INPUT_+']) {
150152
console.log(`::group::installing pkgx input packages`);
151153
let args = process.env['INPUT_+'].split(' ');

installer.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
$ErrorActionPreference = "Stop"
44

5-
# Determine install location
6-
$installDir = "$env:ProgramFiles\pkgx"
5+
# Determine install location for the current user
6+
$installDir = "$env:LOCALAPPDATA\pkgx"
77

88
# Create directory if it doesn't exist
99
if (!(Test-Path $installDir)) {
@@ -17,10 +17,10 @@ Invoke-WebRequest -Uri $zipUrl -OutFile $zipFile
1717
Expand-Archive -Path $zipFile -DestinationPath $installDir -Force
1818
Remove-Item $zipFile
1919

20-
# Ensure PATH is updated
21-
$envPath = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
20+
# Ensure user's PATH is updated
21+
$envPath = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
2222
if ($envPath -notlike "*$installDir*") {
23-
[System.Environment]::SetEnvironmentVariable("Path", "$envPath;$installDir", [System.EnvironmentVariableTarget]::Machine)
23+
[System.Environment]::SetEnvironmentVariable("Path", "$envPath;$installDir", [System.EnvironmentVariableTarget]::User)
2424
}
2525

2626
Write-Host "pkgx installed successfully! Restart your terminal to use it."

installer.sh

Lines changed: 13 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ set -e
55
_main() {
66
if _should_install_pkgx; then
77
_install_pkgx "$@"
8-
_install_pre_reqs
98
elif [ $# -eq 0 ]; then
109
echo /usr/local/bin/"$(pkgx --version) already installed" >&2
1110
echo /usr/local/bin/"$(pkgm --version) already installed" >&2
@@ -47,70 +46,6 @@ _is_ci() {
4746
[ -n "$CI" ] && [ $CI != 0 ]
4847
}
4948

50-
_install_pre_reqs() {
51-
if _is_ci; then
52-
apt() {
53-
# we should use apt-get not apt in CI
54-
# weird shit ref: https://askubuntu.com/a/668859
55-
export DEBIAN_FRONTEND=noninteractive
56-
cmd=$1
57-
shift
58-
$SUDO apt-get $cmd --yes -qq -o=Dpkg::Use-Pty=0 $@
59-
}
60-
else
61-
apt() {
62-
case "$1" in
63-
update)
64-
echo "ensure you have the \`pkgx\` pre-requisites installed:" >&2
65-
;;
66-
install)
67-
echo " apt-get" "$@" >&2
68-
;;
69-
esac
70-
}
71-
yum() {
72-
echo "ensure you have the \`pkgx\` pre-requisites installed:" >&2
73-
echo " yum" "$@" >&2
74-
}
75-
pacman() {
76-
echo "ensure you have the \`pkgx\` pre-requisites installed:" >&2
77-
echo " pacman" "$@" >&2
78-
}
79-
fi
80-
81-
if test -f /etc/debian_version; then
82-
apt update
83-
84-
# minimal but required or networking doesn’t work
85-
# https://packages.debian.org/buster/all/netbase/filelist
86-
A="netbase"
87-
88-
# difficult to pkg in our opinion
89-
B=libudev-dev
90-
91-
# ca-certs needed until we bundle our own root cert
92-
C=ca-certificates
93-
94-
case $(cat /etc/debian_version) in
95-
jessie/sid|8.*|stretch/sid|9.*)
96-
apt install libc-dev libstdc++-4.8-dev libgcc-4.7-dev $A $B $C;;
97-
buster/sid|10.*)
98-
apt install libc-dev libstdc++-8-dev libgcc-8-dev $A $B $C;;
99-
bullseye/sid|11.*)
100-
apt install libc-dev libstdc++-10-dev libgcc-9-dev $A $B $C;;
101-
bookworm/sid|12.*|*)
102-
apt install libc-dev libstdc++-11-dev libgcc-11-dev $A $B $C;;
103-
esac
104-
elif test -f /etc/fedora-release; then
105-
$SUDO yum --assumeyes install libatomic
106-
elif test -f /etc/arch-release; then
107-
# installing gcc isn't my favorite thing, but even clang depends on it
108-
# on archlinux. it provides libgcc. since we use it for testing, the risk
109-
# to our builds is very low.
110-
$SUDO pacman --noconfirm -Sy gcc libatomic_ops libxcrypt-compat
111-
fi
112-
}
113-
11449
_install_pkgx() {
11550
if _is_ci; then
11651
progress="--no-progress-meter"
@@ -122,23 +57,27 @@ _install_pkgx() {
12257

12358
if [ $# -eq 0 ]; then
12459
if [ -f /usr/local/bin/pkgx ]; then
125-
echo "upgrading: /usr/local/bin/pkg[xm]" >&2
60+
echo "upgrading: /usr/local/bin/pkgx" >&2
12661
else
127-
echo "installing: /usr/local/bin/pkg[xm]" >&2
62+
echo "installing: /usr/local/bin/pkgx" >&2
12863
fi
12964

13065
# using a named pipe to prevent curl progress output trumping the sudo password prompt
13166
pipe="$tmpdir/pipe"
13267
mkfifo "$pipe"
13368

134-
curl --silent --fail --proto '=https' -o "$tmpdir/pkgm" \
135-
https://pkgxdev.github.io/pkgm/pkgm.ts
136-
13769
curl $progress --fail --proto '=https' "https://pkgx.sh/$(uname)/$(uname -m)".tgz > "$pipe" &
13870
$SUDO sh -c "
13971
mkdir -p /usr/local/bin
14072
tar xz --directory /usr/local/bin < '$pipe'
141-
install -m 755 "$tmpdir/pkgm" /usr/local/bin
73+
if [ ! -f /usr/local/bin/pkgm ]; then
74+
echo '#!/usr/bin/env -S pkgx -q! pkgm' > /usr/local/bin/pkgm
75+
chmod +x /usr/local/bin/pkgm
76+
fi
77+
if [ ! -f /usr/local/bin/mash ]; then
78+
echo '#!/usr/bin/env -S pkgx -q! mash' > /usr/local/bin/mash
79+
chmod +x /usr/local/bin/mash
80+
fi
14281
" &
14382
wait
14483

@@ -151,7 +90,8 @@ _install_pkgx() {
15190

15291
# tell the user what version we just installed
15392
pkgx --version
154-
pkgm --version
93+
pkgx pkgm@latest --version
94+
pkgx mash@latest --version
15595

15696
else
15797
curl $progress --fail --proto '=https' \
@@ -201,8 +141,4 @@ _should_install_pkgx() {
201141
}
202142

203143
_prep
204-
if [ "$PKGX_INSTALL_PREREQS" != 1 ]; then
205-
_main "$@"
206-
else
207-
_install_pre_reqs
208-
fi
144+
_main "$@"

0 commit comments

Comments
 (0)