11#! /bin/bash
22
33# T&M Hansson IT AB © - 2023, https://www.hanssonit.se/
4- # Copyright © 2021 Simon Lindner (https://github.com/szaimen)
54
65true
7- SCRIPT_NAME=" Face Recognition"
8- SCRIPT_EXPLAINER=" The $SCRIPT_NAME app allows to automatically scan for faces inside your Nextcloud."
6+ SCRIPT_NAME=" Redirect to Recognize"
97# shellcheck source=lib.sh
108source /var/scripts/fetch_lib.sh
119
@@ -15,170 +13,10 @@ source /var/scripts/fetch_lib.sh
1513DEBUG=0
1614debug_mode
1715
18- # Check if root
16+ # Must be root
1917root_check
2018
21- # Check compatibility
22- check_distro_version
23- check_php
24- if [[ " $PHPVER " != " 8.1" ]] && [[ " $PHPVER " != " 7.4" ]]
25- then
26- msg_box " Currently only PHP 7.4 and PHP 8.1 is supported by this script."
27- exit 1
28- fi
19+ # This is because we move the old script to old, and replaced it with this instead.
20+ run_script APP recognize
2921
30- # Encryption may not be enabled
31- if is_app_enabled encryption || is_app_enabled end_to_end_encryption
32- then
33- msg_box " It seems like you have encryption enabled which is unsupported by the $SCRIPT_NAME app!"
34- exit 1
35- fi
36-
37- # Compatible with NC21 and above
38- lowest_compatible_nc 21
39-
40- # Hardware requirements
41- # https://github.com/matiasdelellis/facerecognition/wiki/Requirements-and-Limitations#hardware-requirements
42- # https://github.com/matiasdelellis/facerecognition/wiki/Models#model-3
43- ram_check 2
44- cpu_check 2
45-
46- # Check if facerecognition is already installed
47- if ! is_app_installed facerecognition && ! is_this_installed php7.4-pdlib && ! is_this_installed php8.1-pdli
48- then
49- # Ask for installing
50- install_popup " $SCRIPT_NAME "
51- else
52- # Ask for removal or reinstallation
53- reinstall_remove_menu " $SCRIPT_NAME "
54- # Removal
55- if is_this_installed php7.4-pdlib
56- then
57- apt-get purge php7.4-pdlib -y
58- rm -f /etc/apt/sources.list.d/20-pdlib.list
59- apt-get update -q4 & spinner_loading
60- apt-get autoremove -y
61- rm -f /etc/apt/trusted.gpg.d/facerecognition.gpg
62- elif is_this_installed php8.1-pdlib
63- then
64- apt-get purge php8.1-pdlib -y
65- rm -f /etc/apt/sources.list.d/facerecognition-pdlib.list
66- apt-get update -q4 & spinner_loading
67- apt-get autoremove -y
68- rm -f /etc/apt/keyrings/repo.gpg.key
69- fi
70- crontab -u www-data -l | grep -v " face_background_job.log" | crontab -u www-data -
71- crontab -u www-data -l | grep -v " face:background_job" | crontab -u www-data -
72- if is_app_enabled facerecognition
73- then
74- if yesno_box_no " Do you want to reset all face data?
75- The background scanner will then have to rescan all files for faces when you install the app again."
76- then
77- echo y | nextcloud_occ face:reset --all
78- fi
79- nextcloud_occ config:app:set facerecognition handle_external_files --value false
80- nextcloud_occ config:app:set facerecognition handle_group_files --value false
81- nextcloud_occ config:app:set facerecognition handle_shared_files --value false
82- fi
83- if is_app_installed facerecognition
84- then
85- nextcloud_occ app:remove facerecognition
86- fi
87- rm -f " $VMLOGS " /face_background_job.log
88- # Show successful uninstall if applicable
89- removal_popup " $SCRIPT_NAME "
90- fi
91-
92- # Inform about dependencies
93- msg_box " Please note that the $SCRIPT_NAME app needs an additional PHP dependency \
94- to work which will need to be installed from an external repository.
95- This can set your server under risk."
96- if ! yesno_box_yes " Do you want to install the required dependency?
97- If you choose 'No', the installation will be aborted."
98- then
99- exit 1
100- fi
101-
102- # Install requirements
103- if version 20.04 " $DISTRO " 20.04.10
104- then
105- # https://github.com/matiasdelellis/facerecognition/wiki/PDlib-Installation#ubuntu-focal
106- add_trusted_key_and_repo " repo.gpg.key" \
107- " https://repo.delellis.com.ar" \
108- " https://repo.delellis.com.ar" \
109- " focal focal" \
110- " facerecognition-pdlib.list"
111- install_if_not php" $PHPVER " -pdlib
112- elif version 22.04 " $DISTRO " 22.04.10
113- then
114- # https://github.com/matiasdelellis/facerecognition/wiki/PDlib-Installation#ubuntu-jammy
115- add_trusted_key_and_repo " repo.gpg.key" \
116- " https://repo.delellis.com.ar" \
117- " https://repo.delellis.com.ar" \
118- " $CODENAME $CODENAME " \
119- " facerecognition-pdlib.list"
120- install_if_not php" $PHPVER " -pdlib
121- fi
122-
123- # Install the app
124- install_and_enable_app facerecognition
125- if ! is_app_enabled facerecognition
126- then
127- msg_box " Could not install the $SCRIPT_NAME app. Cannot proceed."
128- exit 1
129- fi
130-
131- # Set up face model and max memory usage
132- # https://github.com/matiasdelellis/facerecognition/wiki/Models#comparison
133- # https://github.com/matiasdelellis/facerecognition/tree/master#initial-setup
134- nextcloud_occ face:setup --memory 2GB
135- nextcloud_occ face:setup --model 3
136-
137- # Set temporary files size
138- nextcloud_occ config:app:set facerecognition analysis_image_area --value=" 4320000"
139-
140- # Additional settings
141- # https://github.com/matiasdelellis/facerecognition/wiki/Settings#hidden-settings
142- if yesno_box_no " Do you want the $SCRIPT_NAME app to scan external storages?
143- This is currently highly inefficient since it will scan all external storges multiple times (once for each user) \
144- and can produce a lot of network traffic.
145- (The scan will need to access all files, also if they are stored externally.)
146- Hence, you should only enable this option if you are only using local external storage \
147- or if you don't use the external storage app at all."
148- then
149- nextcloud_occ config:app:set facerecognition handle_external_files --value true
150- fi
151- if yesno_box_no " Do you want the $SCRIPT_NAME app to scan groupfolders?
152- This is currently highly inefficient since it will scan all groupfolders multiple times (once for each user)."
153- then
154- nextcloud_occ config:app:set facerecognition handle_group_files --value true
155- fi
156- if yesno_box_no " Do you want the $SCRIPT_NAME app to scan shared folders/files?
157- This is currently highly inefficient since it will scan all shared folders/files multiple times (once for each user)."
158- then
159- nextcloud_occ config:app:set facerecognition handle_shared_files --value true
160- fi
161-
162- # Allow the background scanner to scan the files for each user again and enable face scanning for all users
163- # https://github.com/matiasdelellis/facerecognition/wiki/Settings#notes
164- NC_USERS_NEW=$( nextcloud_occ_no_check user:list | sed ' s|^ - ||g' | sed ' s|:.*||' )
165- mapfile -t NC_USERS_NEW <<< " $NC_USERS_NEW"
166- for user in " ${NC_USERS_NEW[@]} "
167- do
168- nextcloud_occ user:setting " $user " facerecognition full_image_scan_done false
169- nextcloud_occ user:setting " $user " facerecognition enabled true
170- done
171-
172- # Make sure that the logfile doesn't get crazy big.
173- crontab -u www-data -l | grep -v " face_background_job.log" | crontab -u www-data -
174- crontab -u www-data -l | { cat; echo " @daily rm -f $VMLOGS /face_background_job.log" ; } | crontab -u www-data -
175-
176- # Schedule background scan
177- # https://github.com/matiasdelellis/facerecognition/wiki/Schedule-Background-Task#cron
178- crontab -u www-data -l | grep -v " face:background_job" | crontab -u www-data -
179- crontab -u www-data -l | { cat; echo " */30 * * * * php -f $NCPATH /occ \
180- face:background_job -t 900 --defer-clustering >> $VMLOGS /face_background_job.log" ; } | crontab -u www-data -
181-
182- msg_box " Congratulations, $SCRIPT_NAME was successfully installed!
183- You just need to wait now and let the background job do its work.
184- After a while, you should see more and more faces that were found in your Nextcloud."
22+ exit
0 commit comments