slackbuilds/n/nextcloud-server/SlackBuild
Gwenhael Le Moine 14b478de9b
use bash
2021-06-15 10:26:26 +02:00

128 lines
3.4 KiB
Bash
Executable file

#!/bin/bash
CWD=$(pwd)
PRGNAM=$(basename $CWD)
RELEASE_TYPE=${RELEASE_TYPE:-releases}
VERSION=${VERSION:-stable}
ARCH="noarch" # hardcode ARCH
BUILD=${BUILD:-1}
TAG=${TAG:-gwh}
VHOST=${VHOST:-vhosts/$PRGNAM/}
VHOSTROOT=/var/www/${VHOST}
DOCROOT=${DOCROOT:-/var/www/${VHOST}htdocs}
DATAROOT=${DATAROOT:-/home/nextcloud/data}
PHPUSER=${PHPUSER:-apache}
PHPGROUP=${PHPGROUP:-apache}
TMP=${TMP:-/tmp/$TAG}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}
set -eu
rm -rf $PKG
mkdir -p $TMP $OUTPUT $PKG/$VHOSTROOT
case $VERSION in
"stable")
wget -c https://download.nextcloud.com/server/${RELEASE_TYPE}/latest.tar.bz2 -O $CWD/nextcloud.tar.bz2
;;
"master")
wget -c https://download.nextcloud.com/server/daily/latest-master.tar.bz2 -O $CWD/nextcloud.tar.bz2
;;
*)
[ ! -e $CWD/nextcloud-$VERSION.tar.bz2 ] && wget -c https://download.nextcloud.com/server/${RELEASE_TYPE}/nextcloud-$VERSION.tar.bz2 -O $CWD/nextcloud.tar.bz2
;;
esac
cd $PKG/$VHOSTROOT
tar xvf $CWD/nextcloud.tar.bz2
rm $CWD/nextcloud.tar.bz2
mv nextcloud htdocs
VERSION=$(grep "Version =" htdocs/version.php | grep -o "[0-9,]*" | tr , .)
cp $CWD/nextcloud-news-updater.rb .
chmod +x nextcloud-news-updater.rb
cd $PKG/$VHOSTROOT/htdocs
chown -R root:root .
find . \
\( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 -o -perm 755 \) \
-exec chmod 750 {} \; -o \
\( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 -o -perm 644 \) \
-exec chmod 640 {} \;
mkdir -p $PKG/usr/doc/$PRGNAM
for i in AUTHORS CONTRIBUTING.md COPYING* README*; do
[ -e $i ] && cp -a $i $PKG/usr/doc/$PRGNAM
done
# Change ownership and perms and create a link.
chown -R $PHPUSER:$PHPGROUP $PKG/$DOCROOT
chmod 0750 $PKG/$DOCROOT
chmod 0770 $PKG/$DOCROOT/{config,apps}
mkdir -p $PKG/etc/logrotate.d/
cat <<EOF > $PKG/etc/logrotate.d/nextcloud.new
$DATAROOT/nextcloud.log {
monthly
rotate 6
delaycompress
compress
notifempty
missingok
}
EOF
mkdir -p $PKG/install
cat <<EOF > $PKG/install/doinst.sh
#!/bin/bash
config() {
NEW="\$1"
OLD="\$(dirname \$NEW)/\$(basename \$NEW .new)"
# If there's no config file by that name, mv it over:
if [ ! -r \$OLD ]; then
mv \$NEW \$OLD
elif [ "\$(cat \$OLD | md5sum)" = "\$(cat \$NEW | md5sum)" ]; then
# toss the redundant copy
rm \$NEW
fi
# Otherwise, we leave the .new copy for the admin to consider...
}
config etc/logrotate.d/nextcloud.new
chown -R $PHPUSER:$PHPGROUP $DOCROOT/apps
grep -q "/var/www/${VHOST}htdocs/cron.php" /var/spool/cron/crontabs/apache || echo "*/15 * * * * php -f /var/www/${VHOST}htdocs/cron.php" >> /var/spool/cron/crontabs/apache
grep -q "/var/www/${VHOST}nextcloud-news-updater.rb" /var/spool/cron/crontabs/apache || echo "*/15 * * * * php -f /var/www/${VHOST}nextcloud-news-updater.rb" >> /var/spool/cron/crontabs/apache
echo "Upgrading database and applications"
( cd /var/www/${VHOST}htdocs/
sudo -u $PHPUSER php ./occ upgrade --quiet --no-interaction
)
echo "Post-installation process completed"
EOF
cat <<EOF > $PKG/install/slack-desc
$PRGNAM: $PRGNAM (self-hosted cloud platform)
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM: http://nextcloud.org
$PRGNAM:
EOF
cd $PKG
rm -f $PKG/{,usr/}lib$(uname -m | grep -o 64)/*.la
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$(echo $VERSION | tr - _)-$ARCH-$BUILD$TAG.${PKGTYPE:-txz}