Skip to content

Instantly share code, notes, and snippets.

@esolitos
Last active July 24, 2017 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esolitos/fc20b80eae87ad81473900388aa553bd to your computer and use it in GitHub Desktop.
Save esolitos/fc20b80eae87ad81473900388aa553bd to your computer and use it in GitHub Desktop.
Find Drupal modules that are not installed, but on the filesystem and do some actions on it.

Find non-useful Drupal modules

This is a collection of scripts will find modules (non core) that are in the codebase which are not installed and report their path. It will skip submodules (using the "project" key in the module info).

#!/bin/bash
# Do not allow runing directly, above statement is jsut for syntaz highlight
exit -1;
# Finds the Not Installed modules, uninstalls them (ask confirm) and removes them form fs
for md in $(drush pml --no-core --status="Not installed" --type=module --pipe); do mdi=$(drush pmi --fields="project, path" --format=csv $md); mdn=$(echo $mdi |cut -d, -f1); mdp=$(echo $mdi |cut -d, -f2); if [ "$md" = "$mdn" -a -d "$mdp" -a ! -z "$mdp" ]; then echo "Removing $mdn at $mdp"; rm -r "$mdp"; fi; done;
# Expanded:
for md in $(drush pml --no-core --status="Not installed" --type=module --pipe); do
mdi=$(drush pmi --fields="project, path" --format=csv $md);
mdn=$(echo $mdi |cut -d, -f1);
mdp=$(echo $mdi |cut -d, -f2);
if [ "$md" = "$mdn" -a -d "$mdp" -a ! -z "$mdp" ]; then
echo "Removing $mdl at $mdp";
rm -r "$mdp";
fi;
done;
#!/bin/bash
# Do not allow runing directly, above statement is jsut for syntaz highlight
exit -1;
# Simply finds modules and prints their path.
for md in $(drush pml --no-core --status="Not installed" --type=module --pipe); do mdi=$(drush pmi --fields="project, path" --format=csv $md); mdn=$(echo $mdi |cut -d, -f1); mdp=$(echo $mdi |cut -d, -f2); if [ "$md" = "$mdn" ]; then echo "Module '$mdn' on path $mdp"; fi; done;
# Expanded:
for md in $(drush pml --no-core --status="Not installed" --type=module --pipe); do
mdi=$(drush pmi --fields="project, path" --format=csv $md);
mdn=$(echo $mdi |cut -d, -f1);
mdp=$(echo $mdi |cut -d, -f2);
if [ "$md" = "$mdn" ]; then
echo "Module '$mdn' on path $mdp";
fi;
done;
#!/bin/bash
# Sorry: No onleline version available, due to increased complexity.
# Finds the DISABLED modules, uninstalls them (ask confirm) and removes them form fs
for md in $(drush pml --no-core --status="disabled" --type=module --pipe); do
mdi=$(drush pmi --fields="project, path" --format=csv $md);
mdn=$(echo $mdi |cut -d, -f1);
mdp=$(echo $mdi |cut -d, -f2);
if [ "$md" = "$mdn" -a -d "$md" -a ! -z "$md" ]; then
while true; do
read -p "Uninstall and remove $md (y/n)?" yn;
if [ $yn = 'y' -o $yn = 'Y' ]; then
drush pm-uninstall "$mdn"
if [ $? -eq 0 ]; then
rm -r "$mdp"
else
echo "ERROR: Uninstall was unsuccessful, leaving codebase untouched"
fi
fi;
if [ $yn = 'n' -o $yn = 'N' ]; then
echo "OK, keeping $mdn"
break;
fi;
done;
fi;
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment