Skip to content

Commit

Permalink
Support default user is not /etc/passwd 's last line
Browse files Browse the repository at this point in the history
  • Loading branch information
whywaita committed Jan 6, 2025
1 parent 618acb2 commit 2087ca5
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lxd.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
diff --git a/images/ubuntu/assets/post-gen/environment-variables.sh b/images/ubuntu/assets/post-gen/environment-variables.sh
index 975c8a4a..016995a1 100644
--- a/images/ubuntu/assets/post-gen/environment-variables.sh
+++ b/images/ubuntu/assets/post-gen/environment-variables.sh
@@ -2,5 +2,5 @@

# Replace $HOME with the default user's home directory for environmental variables related to the default user home directory

-homeDir=$(cut -d: -f6 /etc/passwd | tail -1)
-sed -i "s|\$HOME|$homeDir|g" /etc/environment
\ No newline at end of file
+homeDir=$(cut -d: -f1,6 /etc/passwd | grep "runner:" | cut -d: -f2)
+sed -i "s|\$HOME|$homeDir|g" /etc/environment
diff --git a/images/ubuntu/assets/post-gen/systemd-linger.sh b/images/ubuntu/assets/post-gen/systemd-linger.sh
index 294c8f1b..bfc28952 100644
--- a/images/ubuntu/assets/post-gen/systemd-linger.sh
+++ b/images/ubuntu/assets/post-gen/systemd-linger.sh
@@ -1,5 +1,5 @@
#!/bin/bash

# Enable user session on boot, not on login
-UserId=$(cut -d: -f3 /etc/passwd | tail -1)
+UserId=$(cut -d: -f1,3 /etc/passwd | grep "runner:" | cut -d: -f2)
loginctl enable-linger $UserId
diff --git a/images/ubuntu/scripts/build/configure-environment.sh b/images/ubuntu/scripts/build/configure-environment.sh
index 3c149295..19097573 100644
--- a/images/ubuntu/scripts/build/configure-environment.sh
Expand Down

0 comments on commit 2087ca5

Please sign in to comment.