superbiche
5/12/2016 - 8:53 AM

Bash script to make Drush disable and uninstall a project (module/theme/profile), then delete its directory.

Bash script to make Drush disable and uninstall a project (module/theme/profile), then delete its directory.

#!/bin/sh

project=$1

if [ $# -eq 0 ]; then
    echo "No arguments provided!"
    echo "Usage: drush-pm-remove <project_name>"
    exit 1;
fi

project_dir=$(drush dd $1 2>&1)

if [ -d $project_dir ] && [ $project_dir != $(pwd) ]; then
    echo "Project dir is $project_dir"
    drush dis -y $project 2>&1
    uninstall_status=$(drush pmu -y $project 2>&1)

    if [[ "$uninstall_status" =~ error* ]]; then
        echo "Error while uninstalling $project: "
        echo $uninstall_status
        exit 1;
    fi

    rm -rf $project_dir
    echo "Project $project disabled, uninstalled and deleted!"
else
    echo "Error: Project $project could not be found!"
    exit 1;
fi

exit 0;