2019-11-26 21:42:51 -05:00
|
|
|
#!/usr/bin/env sh
|
2016-07-23 11:46:59 -04:00
|
|
|
|
|
|
|
# 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"
|
|
|
|
|
2018-11-29 23:24:19 -05:00
|
|
|
cd /flarum/app
|
|
|
|
|
2016-07-23 11:46:59 -04:00
|
|
|
# Composer cache dir and packages list paths
|
2018-11-29 22:00:50 -05:00
|
|
|
CACHE_DIR=/flarum/app/extensions/.cache
|
|
|
|
LIST_FILE=/flarum/app/extensions/list
|
2016-07-23 11:46:59 -04:00
|
|
|
|
|
|
|
# Cmd ARGS
|
2018-12-26 15:23:52 -05:00
|
|
|
action="${1}"
|
|
|
|
package="${2}"
|
2016-07-23 11:46:59 -04:00
|
|
|
|
2016-07-23 13:38:13 -04:00
|
|
|
# Create custom extensions cache folder and list file
|
2018-12-26 15:23:52 -05:00
|
|
|
su-exec $UID:$GID mkdir -p "${CACHE_DIR}"
|
|
|
|
su-exec $UID:$GID touch "${LIST_FILE}"
|
2016-07-23 11:46:59 -04:00
|
|
|
|
2018-12-26 15:23:52 -05:00
|
|
|
case "${action}" in
|
2016-07-23 11:46:59 -04:00
|
|
|
# Install a flarum extension
|
|
|
|
"require")
|
2018-12-26 15:23:52 -05:00
|
|
|
COMPOSER_CACHE_DIR="${CACHE_DIR}" composer require "$package"
|
2016-07-23 11:46:59 -04:00
|
|
|
if [ $? -eq 0 ]; then
|
2018-12-26 15:23:52 -05:00
|
|
|
echo "${package}" >> "${LIST_FILE}"
|
2016-07-23 11:46:59 -04:00
|
|
|
echo -e "\n${CGREEN}${package} added to flarum.${CEND}"
|
|
|
|
# Remove duplicate packages
|
2018-12-26 15:23:52 -05:00
|
|
|
sort -u -o "${LIST_FILE}" "${LIST_FILE}"
|
2016-07-23 11:46:59 -04:00
|
|
|
else
|
|
|
|
echo -e "\n${CRED}/!\ An error has occurred...${CEND}"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
# Remove a flarum extension
|
|
|
|
"remove")
|
2018-12-26 15:23:52 -05:00
|
|
|
COMPOSER_CACHE_DIR="$CACHE_DIR" composer remove "${package}"
|
2016-07-23 11:46:59 -04:00
|
|
|
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")
|
2018-12-26 15:23:52 -05:00
|
|
|
cat "${LIST_FILE}"
|
2016-07-23 11:46:59 -04:00
|
|
|
;;
|
|
|
|
# Other composer action
|
|
|
|
*)
|
2018-12-26 15:23:52 -05:00
|
|
|
COMPOSER_CACHE_DIR="${CACHE_DIR}" composer "${@}"
|
2016-07-23 11:46:59 -04:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2018-11-29 22:00:50 -05:00
|
|
|
su-exec $UID:$GID php /flarum/app/flarum cache:clear
|
2016-12-02 02:23:11 -05:00
|
|
|
|
2016-07-23 11:46:59 -04:00
|
|
|
exit 0
|