diff -Nur --no-dereference smeserver-nextcloud-1.2.0.old/root/etc/e-smith/events/actions/nextcloud-conf smeserver-nextcloud-1.2.0/root/etc/e-smith/events/actions/nextcloud-conf --- smeserver-nextcloud-1.2.0.old/root/etc/e-smith/events/actions/nextcloud-conf 2023-01-10 00:53:25.041000000 -0500 +++ smeserver-nextcloud-1.2.0/root/etc/e-smith/events/actions/nextcloud-conf 2023-01-10 00:54:25.821000000 -0500 @@ -1,13 +1,5 @@ #!/bin/bash -function OCC -{ - params=$@; - source /opt/remi/php74/enable - cd /usr/share/nextcloud/ - TERM=dumb /usr/bin/occ $params -} - # does /usr/share/nextcloud exists ? no: we create it from sources if [ ! -d /usr/share/nextcloud ]; then cp -a /usr/share/nextcloud-src /usr/share/nextcloud @@ -46,12 +38,12 @@ res=`/usr/bin/mysql --defaults-file=/root/.my.cnf $socket -e "select count(*) from information_schema.tables where table_type = 'BASE TABLE' and table_schema = '$dbname'" | tail -n1`; if [[ $res == '0' ]]; then - OCC "maintenance:install --database mysql --database-host $host --database-name $dbname --database-user $dbuser --database-pass $password --admin-user $adminuser --admin-pass $adminpass --data-dir /home/e-smith/files/nextcloud/data/" + /usr/bin/occ maintenance:install --database mysql --database-host $host --database-name $dbname --database-user $dbuser --database-pass $password --admin-user $adminuser --admin-pass $adminpass --data-dir /home/e-smith/files/nextcloud/data/ - OCC "app:enable user_ldap" - OCC "ldap:create-empty-config" # create config with empty id - OCC "ldap:create-empty-config" # create config with id s01 - OCC "ldap:delete-config ''" # delte config with empty id + /usr/bin/occ app:enable user_ldap + /usr/bin/occ ldap:create-empty-config # create config with empty id + /usr/bin/occ ldap:create-empty-config # create config with id s01 + /usr/bin/occ ldap:delete-config '' # delete config with empty id mkdir -p /home/e-smith/files/nextcloud/skeleton/ibays /usr/bin/occ config:system:set skeletondirectory --value="/home/e-smith/files/nextcloud/skeleton" #/usr/bin/occ config:system:set templatedirectory --value="" @@ -65,10 +57,9 @@ if [ -f /usr/share/nextcloud/.htaccess.rpmnew ]; then rm -f /usr/share/nextcloud/.htaccess.rpmnew fi - OCC "maintenance:mode --on" - OCC "upgrade" - OCC "maintenance:mode --off" - OCC "integrity:check-core" + /usr/bin/occ upgrade + /usr/bin/occ maintenance:mode --off + /usr/bin/occ integrity:check-core # Catch 'Nextcloud is already latest version' message if [ $? -eq 3 ]; then exit 0 diff -Nur --no-dereference smeserver-nextcloud-1.2.0.old/root/etc/e-smith/events/actions/nextcloud-occ-conf smeserver-nextcloud-1.2.0/root/etc/e-smith/events/actions/nextcloud-occ-conf --- smeserver-nextcloud-1.2.0.old/root/etc/e-smith/events/actions/nextcloud-occ-conf 2023-01-10 00:53:25.049000000 -0500 +++ smeserver-nextcloud-1.2.0/root/etc/e-smith/events/actions/nextcloud-occ-conf 2023-01-10 00:54:16.121000000 -0500 @@ -10,7 +10,7 @@ sub OCC { my $params = join(" ", @_); - system("TERM=dumb /usr/bin/occ $params"); + system("TERM=dumb /usr/bin/occ $params 2>/dev/null"); } sub OCCr @@ -55,6 +55,20 @@ return %NCusers; } +sub listGroups +{ + my %NCgroups; + my $json = JSON->new->allow_nonref->convert_blessed->escape_slash; + my $result = $json->decode(OCCr " group:list -i --output json"); + for my $key (keys %$result){ + my $type = $result->{$key}{'backends'}[0]; + next unless $type eq "LDAP"; + my $subresult = $json->decode(OCCr " group:info $key --output json"); + my $name = $subresult->{'displayName'};# not editable for this backend! + $NCgroups{$name}=$key; + } + return %NCgroups; +} my $cdb = esmith::ConfigDB->open_ro(); my $adb = esmith::AccountsDB->open_ro(); @@ -76,7 +90,8 @@ my $smb = $cdb->get('smb'); $status = $smb->prop('status') || 'disabled'; $status = $nextcloud->prop('UseSMB') || $status; -my %NCusers= listUsers; +my %NCusers; +my %NCgroups; my $storage = ( $status eq "enabled" ) ? 'smb' : 'local' ; my $domain = $cdb->get_value('DomainName'); my $host = $cdb->get_value('SystemName'); @@ -158,13 +173,14 @@ # test new config to make it available, and sync user/groups OCC "ldap:test-config s01"; %NCusers= listUsers; - my $totrash = OCCr "group:list"; + %NCgroups= listGroups; + #my $totrash = OCCr "group:list"; # set ibays shares foreach ( @ibays) { my $group = $_->prop('Group') ||''; my $key = $_->key; - print "Configuring file repo : $key\n"; + #print "Configuring file repo : $key\n"; my $id = ""; my $typ = $_->prop('type'); my @wgroups = split(',', $_->prop('WriteGroups')||''); @@ -183,11 +199,12 @@ next if (grep(/^$key$/i, @excI) ); # get existing mount - %localmounts = listLocalMounts; + %localmounts = listLocalMounts; # search for our current one - my @matching_keys = grep { $localmounts{$_}{'mount_point'} =~ m/^ibays\/$key$/ && $localmounts{$_}{'storage'} eq $storage } keys %localmounts; + my @matching_keys = grep { $localmounts{$_}{'mount_point'} =~ m/ibays\/$key$/ && $localmounts{$_}{'storage'} eq $storage } keys %localmounts; if (scalar(@matching_keys) == 0) { + print "Configuring file repo : $key\n"; #if none create if ($storage eq "smb") { $id = OCCr "files_external:create -c share=$key -c host=localhost -c domain=$workgroup -c root='' -c show_hidden=false -c check_acl=false -c timeout='' 'ibays/$key' smb password::logincredentials --output json"; @@ -195,6 +212,7 @@ $id = OCCr "files_external:create -c datadir=/home/e-smith/files/$typ/$key 'ibays/$key' local null::null --output json"; } for $group (@groups) { + $group = $NCgroups{$group} || next; print " adding group $group to file repo $id\n"; OCC "files_external:applicable --add-group $group $id --output json"; } @@ -225,6 +243,7 @@ print "updating $key\n"; OCC "files_external:applicable --remove-all $id --output json"; for $group (@groups) { + $group = $NCgroups{$group} || next; OCC "files_external:applicable --add-group $group $id --output json" ; } for my $u (@uUsers) { @@ -244,7 +263,7 @@ if( $localmounts{$key}{'mount_point'} =~ m/ibays\/.*$/ && ! exists($params{$key})) { my $mount= $localmounts{$key}{'mount_point'}; print "delete $key : $mount\n"; - OCC "files_external:delete $key -y"; + OCC "files_external:delete -y $key "; } } @@ -294,7 +313,7 @@ print " more than one $key, deleting the latest, keeping first\n"; while (scalar(@matching_keys) > 1){ my $bad = pop @matching_keys; - OCC "files_external:delete $bad -y"; + OCC "files_external:delete -y $bad "; } } $id = pop @matching_keys;