|
@@ -40,7 +40,7 @@ handleServices()
|
|
|
|
|
|
dockerCommand()
|
|
|
{
|
|
|
- validCommands=(start stop restart build ps)
|
|
|
+ validCommands=(start stop restart pull build ps)
|
|
|
if [[ ${validCommands[*]} =~ (^|[[:space:]])"$2"($|[[:space:]]) ]]; then
|
|
|
servicesString=$(handleServices "${@:3}")
|
|
|
if [[ ${servicesString:0:1} == 1 ]]; then
|
|
@@ -57,7 +57,7 @@ dockerCommand()
|
|
|
# shellcheck disable=SC2086
|
|
|
docker-compose up -d ${servicesString}
|
|
|
fi
|
|
|
- if [[ ${2} == "build" || ${2} == "ps" ]]; then
|
|
|
+ if [[ ${2} == "pull" || ${2} == "build" || ${2} == "ps" ]]; then
|
|
|
# shellcheck disable=SC2086
|
|
|
docker-compose "${2}" ${servicesString}
|
|
|
fi
|
|
@@ -92,6 +92,8 @@ if [[ -x "$(command -v docker)" && -x "$(command -v docker-compose)" ]]; then
|
|
|
build)
|
|
|
echo -e "${CYAN}Musare | Build Services${NC}"
|
|
|
# shellcheck disable=SC2068
|
|
|
+ dockerCommand "$(basename "$0")" pull ${@:2}
|
|
|
+ # shellcheck disable=SC2068
|
|
|
dockerCommand "$(basename "$0")" build ${@:2}
|
|
|
;;
|
|
|
|
|
@@ -103,41 +105,55 @@ if [[ -x "$(command -v docker)" && -x "$(command -v docker-compose)" ]]; then
|
|
|
|
|
|
reset)
|
|
|
echo -e "${CYAN}Musare | Reset Services${NC}"
|
|
|
- servicesString=$(handleServices "${@:2}")
|
|
|
- if [[ ${servicesString:0:1} == 1 && ${servicesString:2:4} == "all" ]]; then
|
|
|
- echo -e "${GREEN}Are you sure you want to reset all data? ${YELLOW}[y,n]: ${NC}"
|
|
|
- read -r confirm
|
|
|
- if [[ "${confirm}" == y* ]]; then
|
|
|
- docker-compose stop
|
|
|
- docker-compose rm -v --force
|
|
|
- if [[ -d ".redis" ]]; then
|
|
|
- rm -rf .redis
|
|
|
+ if [[ -f .env ]]; then
|
|
|
+ # shellcheck disable=SC1091
|
|
|
+ source .env
|
|
|
+ servicesString=$(handleServices "${@:2}")
|
|
|
+ if [[ ${servicesString:0:1} == 1 && ${servicesString:2:4} == "all" ]]; then
|
|
|
+ echo -e "${RED}Resetting will remove the ${REDIS_DATA_LOCATION} and ${MONGO_DATA_LOCATION} directories.${NC}"
|
|
|
+ echo -e "${GREEN}Are you sure you want to reset all data? ${YELLOW}[y,n]: ${NC}"
|
|
|
+ read -r confirm
|
|
|
+ if [[ "${confirm}" == y* ]]; then
|
|
|
+ docker-compose stop
|
|
|
+ docker-compose rm -v --force
|
|
|
+ if [[ -d $REDIS_DATA_LOCATION ]]; then
|
|
|
+ rm -rf $REDIS_DATA_LOCATION
|
|
|
+ fi
|
|
|
+ if [[ -d $MONGO_DATA_LOCATION ]]; then
|
|
|
+ rm -rf $MONGO_DATA_LOCATION
|
|
|
+ fi
|
|
|
+ else
|
|
|
+ echo -e "${RED}Cancelled reset${NC}"
|
|
|
fi
|
|
|
- if [[ -d ".db" ]]; then
|
|
|
- rm -rf .db
|
|
|
+ elif [[ ${servicesString:0:1} == 1 ]]; then
|
|
|
+ if [[ "${servicesString:2}" == *redis* && "${servicesString:2}" == *mongo* ]]; then
|
|
|
+ echo -e "${RED}Resetting will remove the ${REDIS_DATA_LOCATION} and ${MONGO_DATA_LOCATION} directories.${NC}"
|
|
|
+ elif [[ "${servicesString:2}" == *redis* ]]; then
|
|
|
+ echo -e "${RED}Resetting will remove the ${REDIS_DATA_LOCATION} directory.${NC}"
|
|
|
+ elif [[ "${servicesString:2}" == *mongo* ]]; then
|
|
|
+ echo -e "${RED}Resetting will remove the ${MONGO_DATA_LOCATION} directory.${NC}"
|
|
|
fi
|
|
|
- else
|
|
|
- echo -e "${RED}Cancelled reset${NC}"
|
|
|
- fi
|
|
|
- elif [[ ${servicesString:0:1} == 1 ]]; then
|
|
|
- echo -e "${GREEN}Are you sure you want to reset all data for $(echo "${servicesString:2}" | tr ' ' ',')? ${YELLOW}[y,n]: ${NC}"
|
|
|
- read -r confirm
|
|
|
- if [[ "${confirm}" == y* ]]; then
|
|
|
- # shellcheck disable=SC2086
|
|
|
- docker-compose stop ${servicesString:2}
|
|
|
- # shellcheck disable=SC2086
|
|
|
- docker-compose rm -v --force ${servicesString:2}
|
|
|
- if [[ "${servicesString:2}" == *redis* && -d ".redis" ]]; then
|
|
|
- rm -rf .redis
|
|
|
- fi
|
|
|
- if [[ "${servicesString:2}" == *mongo* && -d ".db" ]]; then
|
|
|
- rm -rf .db
|
|
|
+ echo -e "${GREEN}Are you sure you want to reset all data for $(echo "${servicesString:2}" | tr ' ' ',')? ${YELLOW}[y,n]: ${NC}"
|
|
|
+ read -r confirm
|
|
|
+ if [[ "${confirm}" == y* ]]; then
|
|
|
+ # shellcheck disable=SC2086
|
|
|
+ docker-compose stop ${servicesString:2}
|
|
|
+ # shellcheck disable=SC2086
|
|
|
+ docker-compose rm -v --force ${servicesString:2}
|
|
|
+ if [[ "${servicesString:2}" == *redis* && -d $REDIS_DATA_LOCATION ]]; then
|
|
|
+ rm -rf $REDIS_DATA_LOCATION
|
|
|
+ fi
|
|
|
+ if [[ "${servicesString:2}" == *mongo* && -d $MONGO_DATA_LOCATION ]]; then
|
|
|
+ rm -rf $MONGO_DATA_LOCATION
|
|
|
+ fi
|
|
|
+ else
|
|
|
+ echo -e "${RED}Cancelled reset${NC}"
|
|
|
fi
|
|
|
else
|
|
|
- echo -e "${RED}Cancelled reset${NC}"
|
|
|
+ echo -e "${RED}${servicesString:2}\n${YELLOW}Usage: $(basename "$0") build [backend, frontend, mongo, redis]${NC}"
|
|
|
fi
|
|
|
else
|
|
|
- echo -e "${RED}${servicesString:2}\n${YELLOW}Usage: $(basename "$0") build [backend, frontend, mongo, redis]${NC}"
|
|
|
+ echo -e "${RED}Error: .env does not exist${NC}"
|
|
|
fi
|
|
|
;;
|
|
|
|
|
@@ -155,11 +171,16 @@ if [[ -x "$(command -v docker)" && -x "$(command -v docker-compose)" ]]; then
|
|
|
if [[ -f .env ]]; then
|
|
|
# shellcheck disable=SC1091
|
|
|
source .env
|
|
|
+ MONGO_VERSION_INT=${MONGO_VERSION:0:1}
|
|
|
if [[ -z $(docker-compose ps -q mongo) ]]; then
|
|
|
echo -e "${RED}Error: Mongo offline, please start to attach.${NC}"
|
|
|
else
|
|
|
echo -e "${YELLOW}Detach with CTRL+C${NC}"
|
|
|
- docker-compose exec mongo mongosh musare -u "${MONGO_USER_USERNAME}" -p "${MONGO_USER_PASSWORD}" --eval "disableTelemetry()" --shell
|
|
|
+ if [[ $MONGO_VERSION_INT -ge 5 ]]; then
|
|
|
+ docker-compose exec mongo mongosh musare -u "${MONGO_USER_USERNAME}" -p "${MONGO_USER_PASSWORD}" --eval "disableTelemetry()" --shell
|
|
|
+ else
|
|
|
+ docker-compose exec mongo mongo musare -u "${MONGO_USER_USERNAME}" -p "${MONGO_USER_PASSWORD}"
|
|
|
+ fi
|
|
|
fi
|
|
|
else
|
|
|
echo -e "${RED}Error: .env does not exist${NC}"
|
|
@@ -285,6 +306,7 @@ if [[ -x "$(command -v docker)" && -x "$(command -v docker-compose)" ]]; then
|
|
|
if [[ -f .env ]]; then
|
|
|
# shellcheck disable=SC1091
|
|
|
source .env
|
|
|
+ MONGO_VERSION_INT=${MONGO_VERSION:0:1}
|
|
|
if [[ $2 == "add" ]]; then
|
|
|
if [[ -z $3 ]]; then
|
|
|
echo -e "${GREEN}Please enter the username of the user you wish to make an admin: ${NC}"
|
|
@@ -295,7 +317,11 @@ if [[ -x "$(command -v docker)" && -x "$(command -v docker-compose)" ]]; then
|
|
|
if [[ -z $adminUser ]]; then
|
|
|
echo -e "${RED}Error: Username for new admin not provided.${NC}"
|
|
|
else
|
|
|
- docker-compose exec mongo mongosh musare -u "${MONGO_USER_USERNAME}" -p "${MONGO_USER_PASSWORD}" --eval "disableTelemetry(); db.users.updateOne({username: '${adminUser}'}, {\$set: {role: 'admin'}})"
|
|
|
+ if [[ $MONGO_VERSION_INT -ge 5 ]]; then
|
|
|
+ docker-compose exec mongo mongosh musare -u "${MONGO_USER_USERNAME}" -p "${MONGO_USER_PASSWORD}" --eval "disableTelemetry(); db.users.updateOne({username: '${adminUser}'}, {\$set: {role: 'admin'}})"
|
|
|
+ else
|
|
|
+ docker-compose exec mongo mongo musare -u "${MONGO_USER_USERNAME}" -p "${MONGO_USER_PASSWORD}" --eval "db.users.updateOne({username: '${adminUser}'}, {\$set: {role: 'admin'}})"
|
|
|
+ fi
|
|
|
fi
|
|
|
elif [[ $2 == "remove" ]]; then
|
|
|
if [[ -z $3 ]]; then
|
|
@@ -307,7 +333,11 @@ if [[ -x "$(command -v docker)" && -x "$(command -v docker-compose)" ]]; then
|
|
|
if [[ -z $adminUser ]]; then
|
|
|
echo -e "${RED}Error: Username for new admin not provided.${NC}"
|
|
|
else
|
|
|
- docker-compose exec mongo mongosh musare -u "${MONGO_USER_USERNAME}" -p "${MONGO_USER_PASSWORD}" --eval "disableTelemetry(); db.users.updateOne({username: '${adminUser}'}, {\$set: {role: 'default'}})"
|
|
|
+ if [[ $MONGO_VERSION_INT -ge 5 ]]; then
|
|
|
+ docker-compose exec mongo mongosh musare -u "${MONGO_USER_USERNAME}" -p "${MONGO_USER_PASSWORD}" --eval "disableTelemetry(); db.users.updateOne({username: '${adminUser}'}, {\$set: {role: 'default'}})"
|
|
|
+ else
|
|
|
+ docker-compose exec mongo mongo musare -u "${MONGO_USER_USERNAME}" -p "${MONGO_USER_PASSWORD}" --eval "db.users.updateOne({username: '${adminUser}'}, {\$set: {role: 'default'}})"
|
|
|
+ fi
|
|
|
fi
|
|
|
else
|
|
|
echo -e "${RED}Invalid command $2\n${YELLOW}Usage: $(basename "$0") admin [add,remove] username${NC}"
|