Skip to content

Instantly share code, notes, and snippets.

@Tetralux
Last active February 24, 2017 22:59
Show Gist options
  • Save Tetralux/55caa6d2012bc296bda51fa372837dd7 to your computer and use it in GitHub Desktop.
Save Tetralux/55caa6d2012bc296bda51fa372837dd7 to your computer and use it in GitHub Desktop.
A simple script to safely back-up the Julia sys.dll and libjulia.dll, and give it a name.
#!/bin/bash
# Moves the sys.dll and libjulia.dll files into sys.$NAME.dll and libjulia.$NAME.dll in their respective directories.
# (See julia-loadimage.sh.)
# If the files already exists, prompts before overwriting.
#
# Usage: ./julia-saveimage.sh <name>
ABORT=0
LIB=usr/lib/julia
BIN=usr/bin
NAME=$1
if [[ `echo $OS | grep Windows` != "" ]]; then
EXT="dll";
else
EXT="so";
fi
if [[ ! -e "$LIB/sys.$EXT" || ! -e "$LIB/sys.o" || ! -e "$BIN/libjulia.$EXT" ]]; then
echo "error: no image or object to save"
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.$NAME.$EXT" || -e "$LIB/sys.$NAME.o" || -e "$BIN/libjulia.$NAME.$EXT" ]]; then
echo -n "files 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.$EXT $LIB/sys.$NAME.$EXT
if [[ $? -ne 0 ]]; then
echo "error: could not copy image file"
ABORT=1
fi
if [[ ABORT -ne 1 ]]; then
cp $LIB/sys.o $LIB/sys.$NAME.o
if [[ $? -ne 0 ]]; then
echo "error: could not copy object file"
ABORT=1
fi
fi
if [[ ABORT -ne 1 ]]; then
cp $BIN/libjulia.$EXT $BIN/libjulia.$NAME.$EXT
if [[ $? -ne 0 ]]; then
echo "error: could not copy libjulia"
ABORT=1
fi
fi
if [[ ABORT -eq 0 ]]; then
rm $LIB/sys.$EXT
rm $LIB/sys.o
rm $BIN/libjulia.$EXT
else
rm $LIB/sys.$NAME.$EXT
rm $LIB/sys.$NAME.o
rm $BIN/libjulia.$NAME.$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