Skip to content
Snippets Groups Projects
remove_module 1.54 KiB
Newer Older
  • Learn to ignore specific revisions
  • Easy Build's avatar
    Easy Build committed
    remove_module()
    {
        echo -e "\nRemoving module: $1"
    
        local ML="$(ml show "$1" 2>&1)"
    
    Easy Build's avatar
    Easy Build committed
        if [ $? != 0 ]; then
            echo "Error: Module not found"
            return 1
        fi
    
        local MODROOT="$(echo "$ML" | grep "EBROOT" | cut -d ',' -f 2 | cut -d '"' -f 2)"
        local MODFILE="$(echo "$ML" | head -n3 | grep "\/[^[:space:]]*:" | tr -d ': ')"
    
    Easy Build's avatar
    Easy Build committed
        echo -ne "[    ] Removing root directory:  $MODROOT"
    
        rm -rf "$MODROOT" 2>&1 >/dev/null
    
    Easy Build's avatar
    Easy Build committed
        if [ $? == 0 ]; then
    	echo -e "\r[\e[32m OK \e[0m] Removing root directory:  $MODROOT"
        else
    	echo -e "\r[\e[31mFAIL\e[0m] Removing root directory:  $MODROOT"
        fi
    
        if [ -L "$MODFILE" ]; then
            local MODFILE2="$(readlink "$MODFILE")"
    
    Easy Build's avatar
    Easy Build committed
        	echo -ne "[    ] Removing link to modfile: $MODFILE"
    
    	rm "$MODFILE" 2>&1 >/dev/null
    
    Easy Build's avatar
    Easy Build committed
        	if [ $? == 0 ]; then
                echo -e "\r[\e[32m OK \e[0m] Removing link to modfile: $MODFILE"
    	else
                echo -e "\r[\e[31mFAIL\e[0m] Removing link to modfile: $MODFILE"
    	fi
    	echo -ne "[    ] Removing modfile:         $MODFILE2"
    
            rm "$MODFILE2" 2>&1 >/dev/null
    
    Easy Build's avatar
    Easy Build committed
            if [ $? == 0 ]; then
                echo -e "\r[\e[32m OK \e[0m] Removing modfile:         $MODFILE2"
            else
                echo -e "\r[\e[31mFAIL\e[0m] Removing modfile:         $MODFILE2"
            fi
        else
            echo -ne "[    ] Removing modfile: $MODFILE\r"
    
            rm "$MODFILE" 2>&1 >/dev/null
    
    Easy Build's avatar
    Easy Build committed
            if [ $? == 0 ]; then
                echo -e "[\e[32m OK \e[0m] Removing modfile: $MODFILE"
            else
                echo -e "[\e[31mFAIL\e[0m] Removing modfile: $MODFILE"
            fi
        fi
    }