Am I correct in assuming that you want a list of the installed apps that you can then use in a script on a fresh installation to batch install them there?
If yes, read ahead, if not, please ignore.
As you know, the output of
occ app:list
is a nice source of information but not an output ready for further use in a script.
In addition, you probably want to have the pre-installed apps excluded from the output.
To get a script useable output with the occ query, we need the command-line JSON processor jq
If not yet installed:
apt install jq
And this is the jq-string to get only the activated aps, without the preinstalled apps:
## preinstalled apps, maintain this list by hand:
exclude_list='["admin_audit", "cloud_federation_api", "comments", "contactsinteraction",
"dashboard", "dav", "encryption", "federatedfilesharing", "federation", "files",
"files_external", "files_sharing", "files_trashbin", "files_versions",
"lookup_server_connector", "oauth2", "provisioning_api", "settings", "sharebymail",
"systemtags", "testing", "theming", "twofactor_backupcodes", "updatenotification",
"user_ldap", "user_status", "weather_status", "workflowengine"]'
## how do we call occ:
# change the webserver-user accordingly
ht_user="www-data"
# change path accordingly:
occ_call="sudo -u $ht_user php -f /var/www/nextcloud/occ"
# your enabled apps
my_enabled_apps="$($occ_call app:list --output=json |
jq --argjson exclude_list "$exclude_list" '.enabled |
keys[] | select(. as $app |
($exclude_list |
index($app) | not)) |
@text' | jq -s 'join(" ")')"
# your disabled apps
my_disabled_apps="$($occ_call app:list --output=json |
jq --argjson exclude_list "$exclude_list" '.disabled |
keys[] | select(. as $app |
($exclude_list |
index($app) | not)) |
@text' | jq -s 'join(" ")')"
# all your apps
my_apps="$my_enabled_apps $my_disabled_apps"
# now you can write it in a file for further use:
echo "$my_apps" > (path/to/)my_apps.txt
You now will have a list of installed apps in one row, separated by spaces, which you can use in a script on your new nextcloud like this:
# in your newly created virtual machine with your fresh installed nextcloud:
# add/change path accordingly:
my_apps_file="(/path/to/)my_apps.txt"
my_apps="$(cat $my_apps_file)"
# pic the options you want, -n looks like a good idea to me:
occ_opts="-n"
# --keep-disabled don't enable the app afterwards
# -f, --force install the app regardless of the Nextcloud version requirement
# --allow-unstable allow installing an unstable releases
# -q, --quiet Do not output any message
# -V, --version Display this application version
# -n, --no-interaction Do not ask any interactive question
# now let occ do the work, without you getting RSI-Syndrom ;)
for app_id in $my_apps; do
$occ_call app:install $occ_opts -- $app_id;
done
As you may have noticed, you can work solely with the enabled apps list as well if you want that. It is all to you and your requirements.
I hope I could help
Even though I have created this post with the greatest possible care, I know with certainty that I (as usual) made at least small mistakes. If you find any inaccuracies please point them out to me, I will correct them immediately if possible or your comment will be the correction.
Happy hacking