Wiki script - Dump sorgenti delle guide: differenze tra le versioni

nessun oggetto della modifica
Nessun oggetto della modifica
Nessun oggetto della modifica
Riga 19: Riga 19:
# Controlla se esiste il file listaguide_source_url
# Controlla se esiste il file listaguide_source_url
if [ ! -f "$file" ]; then
if [ ! -f "$file" ]; then
echo "Il file "$file" non esiste. Uscita."
  echo "Il file "$file" non esiste. Uscita."
  exit 1
  _esci
fi
fi


# Se wget non è installato, lo script termina.
# Se wget non è installato, lo script termina.
if [ ! -f /usr/bin/wget ]; then
if [ -z "$(which wget)" ]; then
echo "wget non è presente. Uscita."
  echo "wget non è presente. Uscita."
  exit 1
  _esci
fi
fi
# Cattura Ctrl+c
trap _esci INT
# Funzione di uscita
_esci () {
  echo
  echo "Script terminato"
  exit 0
}




Riga 39: Riga 49:


# Se il file di dump non esiste, lo script termina
# Se il file di dump non esiste, lo script termina
[ ! -f "$df" ] && echo "$df non esiste" && exit
[ ! -f "$df" ] && echo "$df non esiste" && _esci


echo -n "Inserire il titolo della guida (es. Installare Debian): "
echo -n "Inserire il titolo della guida (es. Installare Debian): "
Riga 51: Riga 61:


if [ -z "`grep "$guida" "$df"`" ]; then
if [ -z "`grep "$guida" "$df"`" ]; then
echo "Guida non trovata" && exit
  echo "Guida non trovata" && exit
else
else
# Sostituisce . con \.
  # Sostituisce . con \.
guida="${guida//"."/"\."}"
  guida="${guida//"."/"\."}"


# Sostituisce & con \&
  # Sostituisce & con \&
guida="${guida//"&"/"\&"}"
  guida="${guida//"&"/"\&"}"


# Sostituisce / con \/
  # Sostituisce / con \/
guida="${guida//"/"/"\/"}"
  guida="${guida//"/"/"\/"}"


# Sostituisce [spazio] con \[spazio]
  # Sostituisce [spazio] con \[spazio]
#guida="${guida//" "/"\ "}"
  #guida="${guida//" "/"\ "}"


# Rimuove da wiki_source la guida con il titolo inserito
  # Rimuove da wiki_source la guida con il titolo inserito
sed -i "/þþþþ/{N; /$guida/ {:a N; /øøøø/! ba;d}}" "$df"
  sed -i "/þþþþ/{N; /$guida/ {:a N; /øøøø/! ba;d}}" "$df"


# File temporaneo
  # File temporaneo
local temp=`mktemp`
  local temp=`mktemp`


# Scarica la guida
  # Scarica la guida
wget -q -O "$temp" "http://$guida2"
  wget -q -O "$temp" "http://$guida2"


echo "þþþþ" >> "$df"
  echo "þþþþ" >> "$df"
echo "$guida2" >> "$df"
  echo "$guida2" >> "$df"
sed -n "/<textarea.*>/{s/^.*\">//;p; :a n; /.*textarea>/!{p;ba}; s/<\/textarea.*//;p}" "$temp" >> "$df"
  sed -n "/<textarea.*>/{s/^.*\">//;p; :a n; /.*textarea>/!{p;ba}; s/<\/textarea.*//;p}" "$temp" >> "$df"
echo "øøøø" >> "$df"
  echo "øøøø" >> "$df"


_lt
  # Chiama la funzione _lt
  _lt


# Rimuove il file temporaneo
  # Rimuove il file temporaneo
rm $temp
  rm $temp


fi
fi
Riga 101: Riga 112:
# Previene l'accidentale sovrascrittura del dump
# Previene l'accidentale sovrascrittura del dump
if [ -f "$df" ]; then
if [ -f "$df" ]; then
echo -n "Esiste già il file "$df". Sovrascrivere [S/n]? "
  echo -n "Esiste già il file "$df". Sovrascrivere [S/n]? "
read risp
  read risp
case $risp in
  case $risp in
  "") rm "$df" ;;
    "") rm "$df" ;;
  [Ss]) rm "$df" ;;
    [Ss]) rm "$df" ;;
  *) exit 1;;
    *) _esci;;
esac
  esac
fi
fi


Riga 121: Riga 132:
read risp
read risp
if [ "$risp" != "S" ] && [ "$risp" != "s" ] && [ "$risp" != "" ]; then
if [ "$risp" != "S" ] && [ "$risp" != "s" ] && [ "$risp" != "" ]; then
exit 1
  _esci
fi
fi


Riga 127: Riga 138:


while read linea; do
while read linea; do
echo "Download della guida $count su un totale di $numerolinee"
  echo "Download della guida $count su un totale di $numerolinee"
tput cuu1
  tput cuu1
((count++))
  ((count++))
wget -q -O "$temp" "$linea"
  wget -q -O "$temp" "$linea"
echo "þþþþ" >> "$df"
  echo "þþþþ" >> "$df"
echo "$linea" >> "$df"
  echo "$linea" >> "$df"
sed -n "/<textarea.*>/{s/^.*\">//;p; :a n; /.*textarea>/!{p;ba}; s/<\/textarea.*//;p}" "$temp" >> "$df"
  sed -n "/<textarea.*>/{s/^.*\">//;p; :a n; /.*textarea>/!{p;ba}; s/<\/textarea.*//;p}" "$temp" >> "$df"
echo "øøøø" >> "$df"
  echo "øøøø" >> "$df"
done < "$file"
done < "$file"


Riga 146: Riga 157:
# Sostituisce "&amp;lt;" con "<" nel file di dump
# Sostituisce "&amp;lt;" con "<" nel file di dump
_lt () {
_lt () {
sed -i 's/&amp;lt;/</g' "$df"
  sed -i 's/&amp;lt;/</g' "$df"
}
}


Riga 161: Riga 172:
[1] Dump di tutte le guide
[1] Dump di tutte le guide
[2] Download di una guida
[2] Download di una guida
[3] Esci
Numero: "
Numero: "


Riga 166: Riga 178:


case $num in
case $num in
1) totaldump ;;
  1) totaldump ;;
2) insertguide ;;
  2) insertguide ;;
  *) _esci ;;
esac
esac


6 999

contributi