File tree 2 files changed +36
-7
lines changed
2 files changed +36
-7
lines changed Original file line number Diff line number Diff line change 4
4
"service" : " app" ,
5
5
"shutdownAction" : " none" ,
6
6
"workspaceFolder" : " /workspace" ,
7
- "postCreateCommand" : [
8
- " ./startupscript/post-startup.sh" ,
9
- " abc" ,
10
- " /config" ,
11
- " ${templateOption:cloud}" ,
12
- " ${templateOption:login}"
13
- ],
7
+ "postCreateCommand" :
8
+ " ./startupscript/post-startup.sh abc /config \" ${templateOption:cloud}\" \" ${templateOption:login}\" ; ./sudo-passwordless.sh abc" ,
14
9
// re-mount bucket files on container start up
15
10
"postStartCommand" : [
16
11
" ./startupscript/remount-on-restart.sh" ,
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ # This script is used to set up passwordless sudo for the core user on the VM.
4
+ # It requires to be run with root priviledges and USER_NAME to be set in the environment.
5
+ # It is typically called from post-startup.sh.
6
+
7
+ USER_NAME=" ${1} "
8
+
9
+ if [[ -z " ${USER_NAME} " ]]; then
10
+ echo " Usage: $0 <username>"
11
+ exit 1
12
+ fi
13
+
14
+ sudoers_file=" /etc/sudoers"
15
+ sudoers_d_file=" /etc/sudoers.d/${USER_NAME} "
16
+
17
+ # Make sure user exists
18
+ if ! id " ${USER_NAME} " & > /dev/null; then
19
+ echo " User ${USER_NAME} does not exist."
20
+ exit 1
21
+ fi
22
+
23
+ # Check if there's an old rule in the main sudoers file that requires a password
24
+ if grep -q " ^${USER_NAME} ALL=(ALL:ALL) ALL" " ${sudoers_file} " ; then
25
+ echo " Found password-requiring rule for ${USER_NAME} in /etc/sudoers. Commenting it out."
26
+
27
+ # Comment out the old rule in /etc/sudoers
28
+ sed -i " s/^${USER_NAME} ALL=(ALL:ALL) ALL/# ${USER_NAME} ALL=(ALL:ALL) ALL/" " ${sudoers_file} "
29
+ fi
30
+
31
+ echo " ${USER_NAME} ALL=(ALL) NOPASSWD:ALL" > " ${sudoers_d_file} "
32
+ chmod 440 " ${sudoers_d_file} "
33
+
34
+ echo " User ${USER_NAME} has been given passwordless sudo access."
You can’t perform that action at this time.
0 commit comments