Skip to content

Commit 95503a4

Browse files
authored
Merge pull request #51 from joshuanianji/edgedb-user-fix
[edgedb] Fix for non-root users
2 parents a071e32 + c9f5ceb commit 95503a4

File tree

6 files changed

+87
-22
lines changed

6 files changed

+87
-22
lines changed

src/edgedb-cli/NOTES.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Shells: `bash`, `zsh`, `fish`
88

99
## Changelog
1010

11-
| Version | Notes |
12-
| ------- | --------------- |
13-
| 1.0.0 | Initial Version |
11+
| Version | Notes |
12+
| ------- | ---------------------- |
13+
| 1.0.1 | Fix for non-root users |
14+
| 1.0.0 | Initial Version |

src/edgedb-cli/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "EdgeDB",
33
"id": "edgedb-cli",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/edgedb-cli",
66
"description": "EdgeDB CLI via the official installation script. Includes the VSCode extension and mounts ~/.local/share/edgedb for data persistence.",
77
"options": {},

src/edgedb-cli/install.sh

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ LIFECYCLE_SCRIPTS_DIR="/usr/local/share/edgedb-cli/scripts"
66

77
set -e
88

9+
# Checks if packages are installed and installs them if not
10+
check_packages() {
11+
if ! dpkg -s "$@" >/dev/null 2>&1; then
12+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
13+
echo "Running apt-get update..."
14+
apt-get update -y
15+
fi
16+
apt-get -y install --no-install-recommends "$@"
17+
fi
18+
}
19+
920
create_cache_dir() {
1021
if [ -d "$1" ]; then
1122
echo "Cache directory $1 already exists. Skip creation..."
@@ -23,36 +34,48 @@ create_cache_dir() {
2334
}
2435

2536
create_symlink_dir() {
26-
# ln -s target_dir source_dir
27-
local source_dir=$1
28-
local target_dir=$2
37+
# local dir is the folder edgedb will use
38+
# cache_dir is the /dc/edgedb-cli folder
39+
local local_dir=$1
40+
local cache_dir=$2
2941
local username=$3
3042

31-
if [ -d "$source_dir" ]; then
32-
echo "Symlink $source_dir to $target_dir..."
33-
ln -s "$source_dir" "$target_dir"
34-
else
35-
echo "Creating source dir $source_dir..."
36-
mkdir -p "$source_dir"
37-
fi
43+
runuser -u "$username" -- mkdir -p "$(dirname "$local_dir")"
44+
runuser -u "$username" -- mkdir -p "$cache_dir"
3845

3946
# if the folder we want to symlink already exists, the ln -s command will create a folder inside the existing folder
40-
if [ -e "$source_dir" ]; then
41-
echo "Moving existing $source_dir folder to $source_dir-old"
42-
mv "$source_dir" "$source_dir-old"
47+
if [ -e "$local_dir" ]; then
48+
echo "Moving existing $local_dir folder to $local_dir-old"
49+
mv "$local_dir" "$local_dir-old"
4350
fi
4451

45-
echo "Symlink $source_dir to $target_dir..."
46-
ln -s "$target_dir" "$source_dir"
52+
echo "Symlink $local_dir to $cache_dir for $username..."
53+
runuser -u "$username" -- ln -s "$cache_dir" "$local_dir"
54+
}
4755

48-
echo "Change owner of $source_dir to $username..."
49-
chown -R "$username:$username" "$source_dir"
56+
install_edgedb() {
57+
local username=$1
58+
59+
echo "Installing EdgeDB CLI..."
60+
curl https://sh.edgedb.com --proto '=https' -sSf1 -o /tmp/edgedb-cli.sh
61+
chmod +x /tmp/edgedb-cli.sh
62+
63+
# install edgedb for a specific user if possible
64+
echo "Installing EdgeDB CLI for $username..."
65+
if [ -z "$username" ]; then
66+
/tmp/edgedb-cli.sh -y
67+
else
68+
runuser -u "$username" -- /tmp/edgedb-cli.sh -y
69+
fi
5070
}
5171

5272
export DEBIAN_FRONTEND=noninteractive
5373

74+
check_packages curl ca-certificates
75+
5476
create_cache_dir "/dc/edgedb-cli" "${USERNAME}"
5577
create_symlink_dir "$_REMOTE_USER_HOME/.local/share/edgedb" "/dc/edgedb-cli" "${USERNAME}"
78+
install_edgedb "${USERNAME}"
5679

5780
# Set Lifecycle scripts
5881
if [ -f oncreate.sh ]; then

test/edgedb-cli/_default.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# This is the default test script that tests everything
6+
# It is not run as a scenario, but is run by other test scripts.
7+
8+
# Optional: Import test library
9+
source dev-container-features-test-lib
10+
11+
# check that the command is available
12+
check "help" bash -c "edgedb --help | grep 'Usage'"
13+
14+
# check that `.config/gh` and `/dc/github-cli` exist under the user (should be node)
15+
check "~/.local/share/edgedb exists" bash -c "ls -la ~/.local/share | grep 'edgedb'"
16+
check "/dc/edgedb-cli exists" bash -c "ls -la /dc | grep 'edgedb-cli'"
17+
18+
# check that the folders are owned by the user
19+
# https://askubuntu.com/a/175060
20+
echo "Checking ownership of ~/.local/share/edgedb and /dc/edgedb-cli (ensure it is owned by $USER)"
21+
ls -al ~/.local/share/
22+
23+
check "~/.local/share/edgedb owned by user" bash -c "test \"$(stat -c "%U" ~/.local/share/edgedb)\" = $USER"
24+
check "/dc/edgedb-cli owned by user" bash -c "test \"$(stat -c "%U" /dc/edgedb-cli)\" = $USER"
25+
26+
# Report result
27+
reportResults

test/edgedb-cli/scenarios.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
{}
1+
{
2+
"with_node": {
3+
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-18",
4+
"features": {
5+
"edgedb-cli": {}
6+
}
7+
}
8+
}

test/edgedb-cli/with_node.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Run default test script (in same folder)
6+
# See: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/test/azure-cli/install_extensions_bookworm.sh
7+
./_default.sh

0 commit comments

Comments
 (0)