58 lines
1.4 KiB
Bash
58 lines
1.4 KiB
Bash
#!/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/extensions/.cache
|
|
LIST_FILE=/flarum/app/extensions/list
|
|
|
|
# Cmd ARGS
|
|
action=$1
|
|
package=$2
|
|
|
|
# Create custom extensions cache folder and list file
|
|
su-exec $UID:$GID mkdir -p "$CACHE_DIR"
|
|
su-exec $UID:$GID touch "$LIST_FILE"
|
|
|
|
case "$action" in
|
|
# Install a flarum extension
|
|
"require")
|
|
COMPOSER_CACHE_DIR="$CACHE_DIR" su-exec $UID:$GID 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 $UID:$GID 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 $UID:$GID composer "$@"
|
|
;;
|
|
esac
|
|
|
|
su-exec $UID:$GID php /flarum/app/flarum cache:clear
|
|
|
|
exit 0
|