Skip to content

Commit caf6bef

Browse files
fix: support non root user and install specified aqua version (#16)
* fix: add a test of non root user * fix: support non root user * refactor: remove unnecessary redirect * refactor: remove debug codes * fix: specify aqua version * fix: use aqua-installer -v option * chore: update version
1 parent 7823c9d commit caf6bef

File tree

5 files changed

+48
-8
lines changed

5 files changed

+48
-8
lines changed

src/aqua-installer/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "aqua-installer",
33
"id": "aqua-installer",
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"description": "Install aqua",
66
"options": {
77
"aqua_version": {

src/aqua-installer/install.sh

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,21 @@ if ! has_command curl && ! has_command wget; then
3030
if has_command apt-get; then
3131
apt-get update -y
3232
apt-get install -y curl
33-
elif has_command apk > /dev/null 2>&1; then
33+
elif has_command apk; then
3434
apk add curl
3535
else
3636
log_error "Neither curl nor wget is found. Please install either curl or wget to download aqua"
3737
exit 1
3838
fi
3939
fi
4040

41-
pwd
42-
ls
43-
4441
url=https://raw.githubusercontent.com/aquaproj/aqua-installer/v3.0.0/aqua-installer
4542

46-
tempdir=$(mktemp -d)
43+
if [ "$_REMOTE_USER" = root ]; then
44+
tempdir=$(mktemp -d)
45+
else
46+
tempdir=$(sudo -u "$_REMOTE_USER" mktemp -d)
47+
fi
4748
cd "$tempdir"
4849

4950
if has_command curl; then
@@ -54,7 +55,22 @@ fi
5455

5556
echo "8299de6c19a8ff6b2cc6ac69669cf9e12a96cece385658310aea4f4646a5496d aqua-installer" | sha256sum -c
5657

57-
chmod +x aqua-installer
58-
./aqua-installer
58+
chmod a+x aqua-installer
59+
if [ "$_REMOTE_USER" = root ]; then
60+
./aqua-installer -v "$AQUA_VERSION"
61+
else
62+
if ! has_command sudo; then
63+
if has_command apt-get; then
64+
apt-get update -y
65+
apt-get install -y sudo
66+
elif has_command apk; then
67+
apk add sudo
68+
else
69+
log_error "Please install sudo to run aqua-installer as $_REMOTE_USER"
70+
exit 1
71+
fi
72+
fi
73+
sudo -u "$_REMOTE_USER" ./aqua-installer -v "$AQUA_VERSION"
74+
fi
5975

6076
rm -R "$tempdir"

test/aqua-installer/alpine-nonroot.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
aqua -v
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM alpine:3.19.1
2+
RUN apk add sudo && \
3+
sed -i "s|# %wheel ALL=(ALL:ALL) NOPASSWD: ALL|%wheel ALL=(ALL:ALL) NOPASSWD: ALL|" /etc/sudoers && \
4+
adduser -u 1000 -G wheel -D vscode && \
5+
rm -rf /var/cache/apk/*
6+
USER vscode

test/aqua-installer/scenarios.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,18 @@
2020
"aqua_version": "v2.27.0"
2121
}
2222
}
23+
},
24+
"alpine-nonroot": {
25+
"build": {
26+
"dockerfile": "Dockerfile"
27+
},
28+
"remoteEnv": {
29+
"PATH": "/home/vscode/.local/share/aquaproj-aqua/bin:${containerEnv:PATH}"
30+
},
31+
"features": {
32+
"aqua-installer": {
33+
"aqua_version": "v2.27.0"
34+
}
35+
}
2336
}
2437
}

0 commit comments

Comments
 (0)