Skip to content

Commit 3394733

Browse files
committed
feat: Add MR_USER_BASE environment variable to override system-wide default for runners' local users base directory
1 parent d8b4693 commit 3394733

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Environment variables:
2626
MR_GIHUB_BASEURL=https://github.com
2727
MR_GIHUB_API_BASEURL=https://api.github.com
2828
MR_RELEASE_URL=<latest on github.com/actions/runner/releases>
29+
MR_USER_BASE=/home
2930
MR_GITHUB_PAT=github_pat_***
3031
3132
Sub-commands:
@@ -45,7 +46,6 @@ Options:
4546
--org GitHub organization name
4647
--repo GitHub repository name, registration on organization-level if empty
4748
--user Linux local username of runner
48-
--base Base directory for user home directories
4949
--labels Extra labels for the runner
5050
--group Runner group for the runner
5151
--token Runner registration token, takes precedence over MR_GITHUB_PAT
@@ -118,6 +118,8 @@ To setup multi-runners, you can simplify run following command multi times:
118118
./mr.bash add --org <ORG-NAME-2>
119119
```
120120

121+
This application will create one Linux local user for one runner via `useradd` command. The *Base Directory* of these users is read from `HOME` setting in your `/etc/default/useradd` file by default (typically `/home`). You can also set it in environment variable `MR_USER_BASE` to override system-wide default.
122+
121123
### List all runners on current host
122124

123125
This application also integrated status check of runners.

mr.bash

+5-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ declare -rg MR_GIHUB_API_BASEURL="${MR_GIHUB_API_BASEURL:-https://api.github.com
2626
declare -rg MR_GIHUB_BASEURL="${MR_GIHUB_BASEURL:-https://github.com}"
2727
# runners' local username prefix, defaults to `runner-`
2828
declare -rg MR_USER_PREFIX="${MR_USER_PREFIX:-runner-}"
29+
# runners' local users base directory, overrides the `HOME` setting in `/etc/default/useradd`
30+
declare -rg MR_USER_BASE="${MR_USER_BASE:-$(useradd -D | grep '^HOME=' | cut -d= -f2-)}"
2931
# URL of this application
3032
declare -rg MR_URL='https://github.com/vbem/multi-runners'
3133

@@ -153,7 +155,7 @@ function mr::addUser {
153155
run::logFailed sudo tee /etc/sudoers.d/runners <<<'%runners ALL=(ALL) NOPASSWD:ALL' >/dev/null \
154156
&& run::logFailed sudo groupadd -f 'runners' >&2 \
155157
&& run::logFailed sudo groupadd -f 'docker' >&2 \
156-
&& run::log sudo useradd -b "${base:-/home}" -m -s /bin/bash -G 'runners,docker' "$user" >&2 || return $?
158+
&& run::log sudo useradd -b "$MR_USER_BASE" -m -s /bin/bash -G 'runners,docker' "$user" >&2 || return $?
157159
echo "$user"
158160
}
159161

@@ -318,6 +320,7 @@ Environment variables:
318320
MR_GIHUB_BASEURL=$MR_GIHUB_BASEURL
319321
MR_GIHUB_API_BASEURL=$MR_GIHUB_API_BASEURL
320322
MR_RELEASE_URL=${MR_RELEASE_URL:-<latest on github.com/actions/runner/releases>}
323+
MR_USER_BASE=$MR_USER_BASE
321324
MR_GITHUB_PAT=${MR_GITHUB_PAT::11}${MR_GITHUB_PAT:+***}
322325
323326
Sub-commands:
@@ -337,7 +340,6 @@ Options:
337340
--org GitHub organization name
338341
--repo GitHub repository name, registration on organization-level if empty
339342
--user Linux local username of runner
340-
--base Base directory for user home directories
341343
--labels Extra labels for the runner
342344
--group Runner group for the runner
343345
--token Runner registration token, takes precedence over MR_GITHUB_PAT
@@ -353,7 +355,7 @@ function mr::main {
353355
local org='' repo='' user='' labels='' token='' group='' dotenv=''
354356

355357
# parse options into variables
356-
getopt_output="$(getopt -o h -l help,org:,repo:,base:,user:,labels:,token:,group:,dotenv: -n "$FILE_THIS" -- "$@")"
358+
getopt_output="$(getopt -o h -l help,org:,repo:,user:,labels:,token:,group:,dotenv: -n "$FILE_THIS" -- "$@")"
357359
log::failed $? "getopt failed!" || return $?
358360
eval set -- "$getopt_output"
359361

@@ -372,10 +374,6 @@ function mr::main {
372374
user="$2"
373375
shift 2
374376
;;
375-
--base)
376-
base="$2"
377-
shift 2
378-
;;
379377
--labels)
380378
labels="$2"
381379
shift 2

0 commit comments

Comments
 (0)