File tree 1 file changed +16
-4
lines changed
1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -91,23 +91,35 @@ function os_user_exists {
91
91
id " $username " > /dev/null 2>&1
92
92
}
93
93
94
- # Create an OS user whose name is $username
94
+ # Create an OS user whose name is $username. If true is passed in as the second arg, run the commands with sudo.
95
95
function os_create_user {
96
96
local -r username=" $1 "
97
+ local -r with_sudo=" $2 "
98
+
99
+ local exuseradd=' useradd'
100
+ if [[ " $with_sudo " == ' true' ]]; then
101
+ exuseradd=' sudo useradd'
102
+ fi
97
103
98
104
if os_user_exists " $username " ; then
99
105
log_info " User $username already exists. Will not create again."
100
106
else
101
107
log_info " Creating user named $username "
102
- useradd " $username "
108
+ " $exuseradd " " $username "
103
109
fi
104
110
}
105
111
106
- # Change the owner of $dir to $username
112
+ # Change the owner of $dir to $username. If true is passed in as the last arg, run the command with sudo.
107
113
function os_change_dir_owner {
108
114
local -r dir=" $1 "
109
115
local -r username=" $2 "
116
+ local -r with_sudo=" $3 "
117
+
118
+ local exchown=' chown'
119
+ if [[ " $with_sudo " == ' true' ]]; then
120
+ exchown=' sudo chown'
121
+ fi
110
122
111
123
log_info " Changing ownership of $dir to $username "
112
- chown -R " $username :$username " " $dir "
124
+ " $exchown " -R " $username :$username " " $dir "
113
125
}
You can’t perform that action at this time.
0 commit comments