set -e

gdthumb=7848
rv_tscroller=8014
openidconnect=7744
community=8160   # FIXME translation already needed?
embedded_videos=7924
bootstrap_darkroom=8261

ORIPWD=$PWD
mkdir -p "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP/usr/local/share"
cd "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP/usr/local/share"
app=$(wget https://api.github.com/repos/Piwigo/Piwigo/releases/latest -q -O - | jq -r '.tag_name')
wget -q "https://github.com/Piwigo/Piwigo/archive/refs/tags/$app.tar.gz"
tar xf *tar.gz
rm -f *tar.gz
mv Piwigo-* piwigo
chown -R root: piwigo
rm -rf piwigo/doc piwigo/README.md  # piwigo/install.php
ln -s /etc/piwigo/config.inc.php piwigo/local/config/config.inc.php
ln -s /etc/piwigo/database.inc.php piwigo/local/config/database.inc.php
ln -s /srv/piwigo/data piwigo/_data
ln -s /srv/piwigo/upload piwigo/upload
ln -s /srv/piwigo/logs piwigo/logs
cp $IMAGE_DIR_RECIPIENT_IMAGE/postinstall/osmmap.php piwigo/
chmod 644 piwigo/osmmap.php
patch -p0 < $IMAGE_DIR_RECIPIENT_IMAGE/postinstall/piwigo.patch
cp $IMAGE_DIR_RECIPIENT_IMAGE/postinstall/piwigo_cli.php piwigo/
# Plugins
cd piwigo/plugins
wget https://piwigo.org/ext/download.php?rid=$gdthumb -O plugin.zip
unzip plugin.zip
rm -f plugin.zip
#
wget https://piwigo.org/ext/download.php?rid=$rv_tscroller -O plugin.zip
unzip plugin.zip
rm -f plugin.zip
#
app=$(wget https://api.github.com/repos/Piwigo/piwigo-openstreetmap/releases/latest -q -O - | jq -r '.tag_name')
wget -q "https://github.com/Piwigo/piwigo-openstreetmap/archive/refs/tags/$app.tar.gz"
tar xf *tar.gz
rm -f *tar.gz
mv piwigo-openstreetmap-* piwigo-openstreetmap
#
wget https://piwigo.org/ext/download.php?rid=$openidconnect -O plugin.zip
unzip plugin.zip
rm -f plugin.zip
# community
wget https://piwigo.org/ext/download.php?rid=$community -O plugin.zip
unzip plugin.zip
rm -f plugin.zip
echo """<?php
\$lang['Edit Photos'] = 'Editer les photos';
\$lang['Edit your photos'] = 'Editer vos photos';
\$lang['Photos posted by %s'] = 'Photos postées par %s';
\$lang['Photos posted by %s in album %s'] = 'Photos postées par %s dans l\'album %s';
\$lang['Select at least one tag'] = 'Sélectionner au moins un tag';
\$lang['Select at least one photo'] = 'Sélectionner au moins une photo';
\$lang['No photo can be deleted'] = 'Aucune photo ne peut être supprimée';
\$lang['You need to confirm deletion'] = 'Vous devez confirmer la suppression';
\$lang['No photo selected, no action possible.'] = 'Aucune photo sélectionnée, aucune action possible.';
?>
""" >> community/language/fr_FR/plugin.lang.php
# embedded
wget https://fr.piwigo.org/ext/download.php?rid=$embedded_videos -O plugin.zip
unzip plugin.zip
rm -f plugin.zip
# user delete photo
#wget https://fr.piwigo.org/ext/download.php?rid=7974 -O plugin.zip
#unzip plugin.zip
#rm -f plugin.zip
# Theme
cd ../themes/
wget https://piwigo.org/ext/download.php?rid=$bootstrap_darkroom -O plugin.zip
unzip plugin.zip
rm -f plugin.zip
ln -s /srv/piwigo/bootstrap_darkroom ../local/bootstrap_darkroom
#
cd $ORIPWD
