Last active
October 16, 2017 08:38
-
-
Save mapio/54c95a3de881409e0ae776ce82a99a04 to your computer and use it in GitHub Desktop.
Installa "firma" nel file .bashrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
rc="$HOME/.bashrc" | |
jars="$HOME/.labprog-jars" | |
if [ ! -w "$rc" ]; then | |
echo "Attenzione, il file .bashrc non era presente, l'installazione potrebbe fallire" | |
fi | |
if grep -q "### labprog-firma (non cancellare questa riga e le seguenti)" "$rc"; then | |
echo "Il comando firma risulta installato, rimuovo la vecchia versione" | |
sed -i '/### labprog-firma (non cancellare questa riga e le seguenti)/,/### labprog-firma (fine/d' "$rc" | |
fi | |
if [ ! -d "$jars" ]; then | |
echo "Creo la directory per le librerie ($jars)" | |
mkdir -p "$jars" | |
fi | |
if [ ! -r "$jars/j4im-0.11-beta.jar" ]; then | |
echo "Scarico ed installo la libreria j4im" | |
curl --progress-bar -o "$jars/j4im-0.11-beta.jar" -L https://github.com/mapio/j4im/releases/download/0.11-beta/j4im-0.11-beta.jar | |
else | |
echo "La libreria j4im risulta installata" | |
fi | |
echo "Installo il comando firma e le definizioni per le variabili d'ambiente" | |
cat <<'OUTEREOF' >>"$rc" | |
### labprog-firma (non cancellare questa riga e le seguenti) | |
firma() { | |
if [ -z "$1" ]; then | |
echo "firma: manca il parametro 'docente/laboratorio/matricola'" >&2 | |
return | |
fi | |
eval $( | |
HOME="$HOME/labprog/$(echo $1 | cut -d/ -f2)" | |
cat <<EOF | python 2>&1 | |
# -*- coding: utf-8 -*- | |
from urllib2 import urlopen, HTTPError | |
try: | |
data = urlopen( 'http://reaper.srv.di.unimi.it/tm/$1' ).read() | |
except HTTPError: | |
print 'echo "firma: il laboratorio richiesto non è ancora stato pubblicato"' | |
else: | |
exec data | |
EOF | |
) | |
} | |
if [ -d "$HOME/labprog/" ]; then | |
export LAST_LAB_PATH=$(ls -1d "$HOME/labprog/"* | sort -r | head -n 1) | |
export PATH="$LAST_LAB_PATH/bin:$PATH" | |
export CLASSPATH="$HOME/.labprog-jars/*:${CLASSPATH:+$CLASSPATH:}." | |
fi | |
### labprog-firma (fine) | |
OUTEREOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment