Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/build/pkgs/jmol/spkg-install
8817 views
#!/usr/bin/env bash
if [ "$SAGE_ROOT" = "" ]; then
   echo "SAGE_ROOT undefined ... exiting";
   echo "Maybe run 'sage -sh'?"
   exit 1
fi

SPKGDIR=`pwd`
echo "Temporary package directory: $SPKGDIR"

# Patches.  Comment out this section if there are none.
if [ ! -d "$SPKGDIR"/patches ]; then
   echo "Error finding patches directory. Exiting."
   exit 1
fi

cp "$SPKGDIR"/patches/Jmol.js "$SPKGDIR"/src/jmol/
if [ $? -ne 0 ]; then
   echo "Error copying Jmol.js patch. Exiting."
   exit 1
fi

cp "$SPKGDIR"/patches/jmol "$SPKGDIR"/src/jmol/
if [ $? -ne 0 ]; then
   echo "Error copying jmol script patch. Exiting."
   exit 1
fi

cp "$SPKGDIR"/patches/testjava.sh "$SPKGDIR"/src/jmol/
if [ $? -ne 0 ]; then
   echo "Error adding testjava.sh to jmol directory. Exiting."
   exit 1
fi

# Check for sagenb location
if [ ! -d "$SAGE_ROOT/devel/sagenb/sagenb/data/jmol" ]; then
    echo "No old Jmol install in notebook. Skipping removal of Jmol from notebook."
else
    echo "Removing Jmol files from the notebook data directory..."
    rm -r "$SAGE_ROOT/devel/sagenb/sagenb/data/jmol"
fi

if [ ! -d "$SAGE_LOCAL"/share/jmol ]; then
    echo "Directory "$SAGE_LOCAL"/share/jmol does not exist.  Creating directory..."
    mkdir "$SAGE_LOCAL/share/jmol"
else
    echo "Deleting all files from "$SAGE_LOCAL"/share/jmol/..."
    rm -r "$SAGE_LOCAL"/share/jmol/*
    echo "Replacing jmol directory and contents..."
fi

# "install" the Jmol files...
cp -r "$SPKGDIR"/src/jmol/* "$SAGE_LOCAL"/share/jmol/

if [ ! -d "$SAGE_LOCAL"/bin ]; then
   echo "Directory "$SAGE_LOCAL"/bin does not exist.  Your Sage install is broken. Exiting."
   exit 1
else
    echo "Copying jmol script to $SAGE_LOCAL/bin."
    cp -f "$SPKGDIR"/src/jmol/jmol "$SAGE_LOCAL"/bin/
    chmod ugo+x "$SAGE_LOCAL"/bin/jmol
fi

echo "Installing applet web directory"
mkdir "$SAGE_LOCAL/share/jmol/appletweb"
cp "$SPKGDIR"/src/jmol/Jmol.js "$SAGE_LOCAL/share/jmol/appletweb"

if [ ! -d "$SPKGDIR"/patches/appletweb ]; then
   echo "Error finding patches/appletweb directory. Exiting."
   exit 1
fi
cp -r "$SPKGDIR"/patches/appletweb/* "$SAGE_LOCAL"/share/jmol/appletweb


if [ $? -ne 0 ]; then
   echo "Error installing Jmol."
   exit 1
else
   echo "New Jmol installed successfully."
fi