Score:3

Unable to install a .sh file

ph flag
AKA

I am trying to use a package called mgl-tools and when I run ./install.sh, it isn't working. It used to work a few days ago.

The error:

./install.sh 
Installing MGLTools to /home/aka/Desktop/Expt 10/mgltools_x86_64Linux2_1.5.7
Installing Python Interpreter to 
tar (child): /home/aka/Desktop/Expt: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
Error in Python installation

The contents of the .sh file:

#!/bin/sh

# MGL Tools installation script
pythonargs=" "
pyoptimize=0
TarDir=`pwd`
export MGL_ROOT=""

# Parse the command-line arguments
opts=`getopt "hlc:d:" "$@"`
if [ "$?" != 0 ]
then
   echo "Usage: source install.sh [-d InstDir] [-c optimization]"
   exit
fi
set -- $opts
while :
do
    case "$1" in 

    -c) shift; pythonargs="$pythonargs -c"; pyoptimize="$1";;
    -d) shift; export MGL_ROOT="$1";;
    -l) pythonargs="$pythonargs -l";;
     
    -h) echo "Optional parameters:"
    echo "[-h]  help message;"
    echo "[ -d  InstDir] specifies installation directory (default-current directory)"
    echo "[ -c optimization] compile Python code with or without optimization:"
    echo "    0 - no optimization (generates .pyc files)"
    echo "    1 - with optimization (generates .pyo files);"
    exit ;;
    --) break;;
    esac
    shift
done

if [ "$MGL_ROOT" != "" ]; then
    # check if the user has write access to the installation directory
    if [ -e "$MGL_ROOT" ]; then
    if [ -d "$MGL_ROOT" ]; then
        if [ ! -w  "$MGL_ROOT" ]; then 
        echo "Can not complete installation - specified directory $MGL_ROOT does not have write access."
        exit 1

        fi
    else 
        echo "$MGL_ROOT" is not a directory
        exit 1
    fi
    else 
    echo Creating directory "$MGL_ROOT"
    mkdir "$MGL_ROOT"
    fi

else
    export MGL_ROOT="$(pwd)"
fi

echo "Installing MGLTools to $MGL_ROOT"

cd "$MGL_ROOT"
echo "Installing Python Interpreter to $MLG_ROOT"
tar xzvf $TarDir/Python*.tar.gz

if [ "$?" != 0 ]; then
    echo "Error in Python installation"
    exit 1
fi
echo Python installed, please wait for the rest of MGLTools to be installed 

cd $TarDir

## plaform we run on

export MGL_ARCHOSV=`$TarDir/Tools/archosv`

## add the path to the directory holding the python interpreter to your path

export PATH="$MGL_ROOT/bin:"$PATH

## use Python interpreter locally installed

PYTHON="$MGL_ROOT/bin/python"
export PYTHONHOME="$MGL_ROOT"
if [ "`uname -s`" = "Linux" ] ; then
    export LD_LIBRARY_PATH="$MGL_ROOT/lib"
fi

## run python script - install.py - to install MGL packages and create pmv , adt, and vision scripts

if [ "$pyoptimize" -eq 1 ]; then
    echo "Running $PYTHON -O Tools/install.py $pythonargs"
    $PYTHON -O Tools/install.py $pythonargs
else
    echo "Running $PYTHON Tools/install.py $pythonargs"
    $PYTHON Tools/install.py  $pythonargs
fi

unset PYTHONHOME
N0rbert avatar
zw flag
What is your Ubuntu version?
AKA avatar
ph flag
AKA
Ubuntu 20.04.3 LTS
us flag
What is the content of the .sh file? Please copy paste text instead of posting screenshots. Also edit the question to add thee information, don't post them in the comments.
Score:5
cn flag

Shell scripts do not like spaces in names. Please try renaming your directory EXPT 10 to a name without spaces; for example, EXPT10 and then try again.

EDIT: As @cocomac correctly points out, properly written scripts can and should account for spaces in names. If yours does not, renaming the file is the expedient solution. Rewriting the script and filing an issue with the publisher is another solution.

cocomac avatar
cn flag
@AKA In theory, a well-designed shell script [can handle spaces just fine](https://unix.stackexchange.com/q/131766/495409). This one doesn't (they forgot to quote a variable, which they would have discovered had the author(s) [ran it through ShellCheck](https://www.shellcheck.net/). If the script was written with proper quoting (which it wasn't), it should be able to handle spaces just fine. I disagree with chili555, a properly designed script should be able to handle space just fine.
chili555 avatar
cn flag
@cocomac Thanks for the additional insight. I have added and edit. I feel that the most practical solution for the typical AU user is renaming, not modifying the code.
cocomac avatar
cn flag
Welcome! I certainly agree, modifying (installer) shell scripts is complex and isn't very practical for the average user, I just wanted to point out that shell scripts more generally can handle spaces, when programmed correctly
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.