Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,17 @@ auth:
uid: 1000
gid: 1000
password: bar
groups: [qux, quux]
- user: baz
group: xxx
uid: 1100
gid: 1200
password_file: /run/secrets/baz_password

group:
qux: 2001
quux: 2002

global:
- "force user = foo"
- "force group = foo"
Expand Down
19 changes: 19 additions & 0 deletions rootfs/etc/cont-init.d/01-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ bind interfaces only = yes
EOL
fi

if [[ "$(yq --output-format=json e '(.. | select(tag == "!!str")) |= envsubst' "${CONFIG_FILE}" 2>/dev/null | jq '.group')" != "null" ]]; then
for group_entry in $(yq -j e '(.. | select(tag == "!!str")) |= envsubst' "${CONFIG_FILE}" 2>/dev/null | jq -r '.group | to_entries[] | @base64'); do
_jq() {
echo "${group_entry}" | base64 --decode | jq -r "${1}"
}
group_name=$(_jq '.key')
group_id=$(_jq '.value')
echo "Creating group $group_name with GID $group_id"
id -g "$group_id" &>/dev/null || id -gn "$group_name" &>/dev/null || addgroup -g "$group_id" -S "$group_name"
done
fi

if [[ "$(yq --output-format=json e '(.. | select(tag == "!!str")) |= envsubst' "${CONFIG_FILE}" 2>/dev/null | jq '.auth')" != "null" ]]; then
for auth in $(yq -j e '(.. | select(tag == "!!str")) |= envsubst' "${CONFIG_FILE}" 2>/dev/null | jq -r '.auth[] | @base64'); do
_jq() {
Expand All @@ -121,6 +133,13 @@ if [[ "$(yq --output-format=json e '(.. | select(tag == "!!str")) |= envsubst' "
echo "Creating user $(_jq '.user')/$(_jq '.group') ($(_jq '.uid'):$(_jq '.gid'))"
id -g "$(_jq '.gid')" &>/dev/null || id -gn "$(_jq '.group')" &>/dev/null || addgroup -g "$(_jq '.gid')" -S "$(_jq '.group')"
id -u "$(_jq '.uid')" &>/dev/null || id -un "$(_jq '.user')" &>/dev/null || adduser -u "$(_jq '.uid')" -G "$(_jq '.group')" "$(_jq '.user')" -SHD
groups=$(_jq '.groups')
if [[ "$groups" != "null" ]]; then
for group_name in $(echo "$groups" | jq -r '.[]'); do
echo "Adding user $(_jq '.user') to group $group_name"
addgroup "$(_jq '.user')" "$group_name"
done
fi
echo -e "$password\n$password" | smbpasswd -a -s "$(_jq '.user')"
unset password
done
Expand Down
5 changes: 5 additions & 0 deletions test/data/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ auth:
uid: 1000
gid: 1000
password: bar
groups: [qux, quux]
- user: yyy
group: xxx
uid: 1100
gid: 1200
password_file: /tmp/yyy_password

group:
qux: 2001
quux: 2002

global:
- "force user = foo"
- "force group = foo"
Expand Down