From f23f3db38b0791a79b16d7508ffc6cefd586c123 Mon Sep 17 00:00:00 2001 From: Hardware Date: Sat, 23 Jul 2016 17:46:59 +0200 Subject: [PATCH] feat(): add extensions management script --- Dockerfile | 3 ++- README.md | 22 +++++++++++++++++++++ composer | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ startup | 14 ++++++++++++++ 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 composer diff --git a/Dockerfile b/Dockerfile index dbb8b0a..6791080 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,8 +41,9 @@ COPY php-fpm.conf /etc/php7/php-fpm.conf COPY opcache.ini /etc/php7/conf.d/00_opcache.ini COPY supervisord.conf /etc/supervisor/supervisord.conf COPY startup /usr/local/bin/startup +COPY composer /usr/local/bin/composeur -RUN chmod +x /usr/local/bin/startup +RUN chmod +x /usr/local/bin/* VOLUME /flarum/app/assets EXPOSE 8080 diff --git a/README.md b/README.md index 14aa9b2..2441047 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,28 @@ docker-compose up -d * **Username** : *admin* * **Password** : *password* +### Install custom extensions + +**Flarum extensions list :** https://packagist.org/search/?q=flarum-ext + +#### Install an extension + +``` +docker exec -ti flarum composeur require some/extension +``` + +#### Remove an extension + +``` +docker exec -ti flarum composeur remove some/extension +``` + +#### List all extensions + +``` +docker exec -ti flarum composeur list +``` + ### Screenshot ![flarum](https://i.imgur.com/teqg3od.pngP) diff --git a/composer b/composer new file mode 100644 index 0000000..4363fa4 --- /dev/null +++ b/composer @@ -0,0 +1,57 @@ +#!/bin/sh + +# COMPOSER WRAPUP SCRIPT +# This script allow to add new extensions to flarum + +CSI="\033[" +CEND="${CSI}0m" +CRED="${CSI}1;31m" +CGREEN="${CSI}1;32m" + +# Composer cache dir and packages list paths +CACHE_DIR=/flarum/app/assets/.extensions +LIST_FILE=assets/.extensions/list + +# Cmd ARGS +action=$1 +package=$2 + +# Move to flarum folder +cd /flarum/app + +# Create custom extensions cache folder +su-exec flarum:flarum mkdir -p "$CACHE_DIR" + +case "$action" in + # Install a flarum extension + "require") + COMPOSER_CACHE_DIR="$CACHE_DIR" su-exec flarum:flarum composer require "$package" + if [ $? -eq 0 ]; then + echo "$package" >> "$LIST_FILE" + echo -e "\n${CGREEN}${package} added to flarum.${CEND}" + # Remove duplicate packages + sort -u -o "$LIST_FILE" "$LIST_FILE" + else + echo -e "\n${CRED}/!\ An error has occurred...${CEND}" + fi + ;; + # Remove a flarum extension + "remove") + COMPOSER_CACHE_DIR="$CACHE_DIR" su-exec flarum:flarum composer remove "$package" + if [ $? -eq 0 ]; then + sed -i "\|${package}|d" "$LIST_FILE" + echo -e "\n${CGREEN}${package} removed from flarum${CEND}" + else + echo -e "\n${CRED}/!\ An error has occurred...${CEND}" + fi + ;; + "list") + cat "$LIST_FILE" + ;; + # Other composer action + *) + COMPOSER_CACHE_DIR="$CACHE_DIR" su-exec flarum:flarum composer "$@" + ;; +esac + +exit 0 diff --git a/startup b/startup index e5e95a9..e22ea02 100644 --- a/startup +++ b/startup @@ -86,6 +86,20 @@ else # Init flarum (without steps above) su-exec flarum:flarum php flarum install --file config.yml + # Composer cache dir and packages list paths + CACHE_DIR=/flarum/app/assets/.extensions + LIST_FILE=assets/.extensions/list + + # Download extra extensions installed with composer wrapup script + if [ -s "$LIST_FILE" ]; then + echo "[INFO] Install extra bundled extensions" + while read extension; do + echo "[INFO] -------------- Install extension : ${extension} --------------" + COMPOSER_CACHE_DIR="$CACHE_DIR" su-exec flarum:flarum composer require "$extension" + done < "$LIST_FILE" + echo "[INFO] Install extra bundled extensions. DONE." + fi + echo "[INFO] Init done, launch flarum..." fi