diff --git a/src/freedombone-utils-nodejs b/src/freedombone-utils-nodejs index 89e3a81b..1d2541bf 100755 --- a/src/freedombone-utils-nodejs +++ b/src/freedombone-utils-nodejs @@ -36,6 +36,10 @@ VARIANTS='mesh' NODEJS_VERSION='6.2.2' NODEJS_N_VERSION='2.1.4' +# This file keeps track of the apps needing nodejs +# so that it can be removed if tere are no apps which need it +NODEJS_INSTALLED_APPS_FILE=$HOME/.nodejs-apps + function mesh_install_nodejs { chroot "${rootdir}" apt-get -yq install nodejs chroot "${rootdir}" apt-get -yq install npm curl @@ -65,6 +69,31 @@ EOF chroot "${rootdir}" rm -f /root/install-nodejs.sh } +function remove_nodejs { + if [ ! $1 ]; then + return + fi + if [ ! -f $NODEJS_INSTALLED_APPS_FILE ]; then + return + fi + sed -i "/install_${1}/d" $NODEJS_INSTALLED_APPS_FILE + if ! grep "install_" $NODEJS_INSTALLED_APPS_FILE; then + apt-get -yq remove --purge nodejs + + if [ -f /usr/bin/nodejs ]; then + rm /usr/bin/nodejs + fi + if [ -f /usr/local/bin/node ]; then + rm /usr/local/bin/node + fi + if [ -f /usr/bin/node ]; then + rm /usr/bin/node + fi + + rm $NODEJS_INSTALLED_APPS_FILE + fi +} + function install_nodejs { if [ $INSTALLING_MESH ]; then mesh_install_nodejs @@ -101,6 +130,12 @@ EOF fi rm -f /root/install-nodejs.sh + if [ $1 ]; then + if ! grep "install_${1}" $NODEJS_INSTALLED_APPS_FILE; then + echo "install_${1}" >> $NODEJS_INSTALLED_APPS_FILE + fi + fi + mark_completed $FUNCNAME }