Skip to content

Instantly share code, notes, and snippets.

@Tetralux
Last active February 24, 2017 22:58
Show Gist options
  • Save Tetralux/a890cc4738e6d753132c1315a6f966e3 to your computer and use it in GitHub Desktop.
Save Tetralux/a890cc4738e6d753132c1315a6f966e3 to your computer and use it in GitHub Desktop.
A simple script to safely load a back-up of the Julia sys.dll and libjulia.dll.
#!/bin/bash
# Moves libjulia.$NAME.dll and sys.$NAME.dll back into place. (See julia-saveimage.sh.)
# If the files already exist, prompts before overwriting.
#
# Usage: ./julia-loadimage.sh <name>
LIB=usr/lib/julia
BIN=usr/bin
ABORT=0
NAME=$1
if [[ `echo $OS | grep Windows` != "" ]]; then
EXT="dll";
else
EXT="so";
fi
if [[ ! -e "$LIB/sys.$NAME.$EXT" || ! -e "$LIB/sys.$NAME.o" || ! -e "$BIN/libjulia.$NAME.$EXT" ]]; then
echo "error: no image and object named $NAME"
ABORT=1
fi
if [[ ABORT -ne 1 && "$NAME" == "" ]]; then
echo "error: no name provided"
ABORT=1
fi
if [[ ABORT -ne 1 ]]; then
if [[ -e "$LIB/sys.$EXT" || -e "$LIB/sys.o" || -e "$BIN/libjulia.$EXT" ]]; then
echo -n "current image and object would be overwritten. proceed? [Y,N] "
read i
if [[ "$i" == "n" || "$i" == "N" ]]; then
ABORT=1
fi
fi
fi
if [[ ABORT -eq 0 ]]; then
cp $LIB/sys.$NAME.$EXT $LIB/sys.$EXT
if [[ $? -ne 0 ]]; then
echo "error: could not copy image file into place"
ABORT=1
fi
if [[ ABORT -ne 1 ]]; then
cp $LIB/sys.$NAME.o $LIB/sys.o
if [[ $? -ne 0 ]]; then
echo "error: could not copy object file into place"
ABORT=1
fi
fi
if [[ ABORT -ne 1 ]]; then
cp $BIN/libjulia.$NAME.$EXT $BIN/libjulia.$EXT
if [[ $? -ne 0 ]]; then
echo "error: could not copy libjulia into place"
ABORT=1
fi
fi
if [[ ABORT -eq 0 ]]; then
rm $LIB/sys.$NAME.$EXT
rm $LIB/sys.$NAME.o
rm $BIN/libjulia.$NAME.$EXT
else
rm $LIB/sys.$EXT
rm $LIB/sys.o
rm $BIN/libjulia.$EXT
fi
fi
if [[ ABORT -eq 1 ]]; then
echo "quit"
fi
exit $ABORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment