#!/bin/sh -e # __nextcloud_user/gencode-remote # Call the nextcloud occ script as the designed user. Maybe this can be a bit # more effictive with user switching, but currently the easiest way of doing # it. # # All arguments are directly passed to occ (injection alarm ;-) ) occ() { # su creates a new shell, so it does not affect the current session # will not use -q as it supresses errors, too cat << SHELL su -s /bin/sh -l "$www_user" -- -e <<'SU' cd '$cloud' && php occ --no-warnings --no-interaction --no-ansi $@ SU SHELL } # Creates the output for the nextcloud command to create a user. Takes all # required parameters from existing variables. occ_create() { cat <> "$__messages_out" else occ_create echo created >> "$__messages_out" fi ;; disabled) if [ "$state_is" = "absent" ]; then occ_create echo created >> "$__messages_out" fi occ user:disable "'$user'" echo disabled >> "$__messages_out" ;; present) if [ "$state_is" = "absent" ]; then occ_create echo created >> "$__messages_out" fi # else, everything is ok ;; absent) occ user:delete "'$user'" echo removed >> "$__messages_out" ;; esac fi # Check if the user should not be modified further from the initial setup. if [ -f "$__object/parameter/only-setup" ]; then ignore_config="yes" fi # Check if some user configuration should be changed # do not run this code if the user will be created in the previous code if [ "$state_should" != "absent" ] && [ "$ignore_config" != "yes" ]; then if ! [ -f "$__object/parameter/keep-displayname" ]; then # Check if the display name is correct if someone is set if [ -f "$__object/parameter/displayname" ]; then displayname="$(cat "$__object/parameter/displayname")" if ! match_param display_name "$displayname"; then cat <getUserSession()->getManager()->get("$user")->setDisplayName("$displayname") or print("Couldn'\''t modify $user display name! Maybe unsupported or already set ..".PHP_EOL) and die(1);' SU SHELL fi fi # the display name can not be unset fi if ! [ -f "$__object/paramter/keep-email" ]; then # Check if the email address is correct if [ -f "$__object/parameter/email" ]; then email="$(cat "$__object/parameter/email")" if ! match_param email "$email"; then occ user:setting -- "'$user'" settings email "'$email'" fi else # remove if it doesn't exist if ! match_param email ""; then occ user:setting --delete -- "'$user'" settings email fi fi fi if ! [ -f "$__object/parameter/keep-password" ]; then # Check state of the password # explorer handles missing passwords already if [ "$(cat "$__object/explorer/password")" = "mismatched" ]; then cat < "$__object/files/explorer_groups" # Add/Remove groups not set via the parameter if [ -s "$__object/parameter/group" ]; then # Get all groups to remove grep -Fxv -f "$__object/parameter/group" \ "$__object/files/explorer_groups" > "$__object/files/group.del" || true # Get all groups to add grep -Fxv -f "$__object/files/explorer_groups" \ "$__object/parameter/group" > "$__object/files/group.add" || true # No user groups at all if nothing wanted by the user else # remove all groups to stay inline with the user parameter cp "$__object/files/explorer_groups" "$__object/files/group.del" fi # Remove all groups not exist anymore if [ -s "$__object/files/group.del" ]; then while read -r GROUP; do occ group:removeuser "'$GROUP'" "'$user'" done < "$__object/files/group.del" fi # Add all existing groups if [ -s "$__object/files/group.add" ]; then while read -r GROUP; do occ group:adduser "'$GROUP'" "'$user'" done < "$__object/files/group.add" fi fi # These parameters are only set if they exist # ... fi