From cd028274ab58c662bdeaebcc48cd96864178f609 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Sat, 11 Aug 2018 16:55:24 -0400 Subject: [PATCH] Plugin utility functions, increased version number --- package.json | 2 +- plugins/.gitignore | 1 + start.sh | 27 +++++++++++++--- webodm.sh | 76 +++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 99 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index c0bc4d17..f6f76983 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "WebODM", - "version": "0.6.0", + "version": "0.6.1", "description": "Open Source Drone Image Processing", "main": "index.js", "scripts": { diff --git a/plugins/.gitignore b/plugins/.gitignore index 6de001d8..ff22c659 100644 --- a/plugins/.gitignore +++ b/plugins/.gitignore @@ -1 +1,2 @@ webpack.config.js +disabled diff --git a/start.sh b/start.sh index c0401fba..8df18489 100755 --- a/start.sh +++ b/start.sh @@ -51,6 +51,9 @@ if [ "$1" = "--setup-devenv" ] || [ "$2" = "--setup-devenv" ]; then webpack --watch & fi +echo Cleaning up plugins +./webodm.sh plugin cleanup + echo Running migrations python manage.py migrate @@ -74,11 +77,25 @@ cat app/scripts/unlock_all_tasks.py | python manage.py shell congrats(){ (sleep 5; echo - echo -e "\033[92m" - echo "Congratulations! └@(・◡・)@┐" - echo ========================== - echo -e "\033[39m" - echo "If there are no errors, WebODM should be up and running!" + + echo "Trying to establish communication..." + status=$(curl --max-time 300 -L -s -o /dev/null -w "%{http_code}" "$proto://localhost:8000") + + if [[ "$status" = "200" ]]; then + echo -e "\033[92m" + echo "Congratulations! └@(・◡・)@┐" + echo ========================== + echo -e "\033[39m" + echo "If there are no errors, WebODM should be up and running!" + else + echo -e "\033[93m" + echo "Something doesn't look right! ¯\_(ツ)_/¯" + echo "The server returned a status code of $status when we tried to reach it." + echo ========================== + echo -e "\033[39m" + echo "Check if WebODM is running, maybe we tried to reach it too soon." + fi + echo -e "\033[93m" echo Open a web browser and navigate to $proto://$WO_HOST:$WO_PORT echo -e "\033[39m" diff --git a/webodm.sh b/webodm.sh index bea096fb..e9f0a05e 100755 --- a/webodm.sh +++ b/webodm.sh @@ -98,7 +98,12 @@ usage(){ echo " rebuild Rebuild all docker containers and perform cleanups" echo " checkenv Do an environment check and install missing components" echo " test Run the unit test suite (developers only)" - echo " resetadminpassword Reset the administrator's password to a new one. WebODM must be running when executing this command." + echo " resetadminpassword Reset the administrator's password to a new one. WebODM must be running when executing this command." + echo "" + echo " plugin enable Enable a plugin" + echo " plugin disable Disable a plugin" + echo " plugin list List all available plugins" + echo " plugin cleanup Cleanup plugins build directories" echo "" echo "Options:" echo " --port Set the port that WebODM should bind to (default: $DEFAULT_PORT)" @@ -218,6 +223,7 @@ down(){ rebuild(){ run "docker-compose down --remove-orphans" + plugin_cleanup run "rm -fr node_modules/ || sudo rm -fr node_modules/" run "rm -fr nodeodm/external/node-OpenDroneMap || sudo rm -fr nodeodm/external/node-OpenDroneMap" run "docker-compose -f docker-compose.yml -f docker-compose.build.yml build --no-cache" @@ -225,6 +231,54 @@ rebuild(){ echo -e "\033[1mDone!\033[0m You can now start WebODM by running $0 start" } +plugin_cleanup(){ + # Delete all node_modules and build directories within plugins' public/ folders + find plugins/ -type d \( -name build -o -name node_modules \) -path 'plugins/*/public/*' -exec rm -frv '{}' \; 2>/dev/null +} + +plugin_list(){ + plugins=$(ls plugins/ --hide test) + for plugin in $plugins; do + if [ -e "plugins/$plugin/disabled" ]; then + echo "$plugin [disabled]" + else + echo "$plugin" + fi + done +} + +plugin_check(){ + plugin_name="$1" + if [ ! -e "plugins/$plugin_name" ]; then + echo "Plugin $plugin_name does not exist." + exit 1 + fi +} + +plugin_enable(){ + plugin_name="$1" + plugin_check $plugin_name + + if [ -e "plugins/$plugin_name/disabled" ]; then + rm "plugins/$plugin_name/disabled" + echo "Plugin enabled. Run ./webodm.sh restart to apply the changes." + else + echo "Plugin already enabled." + fi +} + +plugin_disable(){ + plugin_name="$1" + plugin_check $plugin_name + + if [ ! -e "plugins/$plugin_name/disabled" ]; then + touch "plugins/$plugin_name/disabled" + echo "Plugin disabled. Run ./webodm.sh restart to apply the changes." + else + echo "Plugin already disabled." + fi +} + run_tests(){ echo -e "\033[1mRunning frontend tests\033[0m" run "npm run test" @@ -291,6 +345,26 @@ elif [[ $1 = "test" ]]; then run_tests elif [[ $1 = "resetadminpassword" ]]; then resetpassword $2 +elif [[ $1 = "plugin" ]]; then + if [[ $2 = "cleanup" ]]; then + plugin_cleanup + elif [[ $2 = "list" ]]; then + plugin_list + elif [[ $2 = "enable" ]]; then + if [[ ! -z "$3" ]]; then + plugin_enable $3 + else + usage + fi + elif [[ $2 = "disable" ]]; then + if [[ ! -z "$3" ]]; then + plugin_disable $3 + else + usage + fi + else + usage + fi else usage fi