scripts/scan-st/scan.sh

220 lines
5.0 KiB
Bash
Executable File

#!/bin/bash
# Laisser la boucle ci-dessous car elle permet au script de se répéter en entier
while :; do
count=
# Chemin par défaut
defpath="/home/t0mux/Cloud/1-ATELIER/1-ST"
# defpath="./scantest" # TEST
# Type document
while true; do
clear
echo "# Type de document ?";echo
echo " 1) PV"
echo " 2) BT"
echo " 3) Autre";echo
echo " G) Scanner via GUI"
echo -e " C) Changer le chemin de sortie (${defpath})\n"
if [ ! -z ${type} ]; then echo " i) Idem précédent ($type)"; fi
read -n1 -p ">" ntype
echo
case $ntype in
1) type=PV;break
;;
2) type=BT;break
;;
3) read -p "Type=" type;break
;;
c|C) if [ -f /usr/bin/zenity ]
then defpath=$(zenity --file-selection --directory)
else echo -e "\nZenity n'est pas installé, impossible de changer le chemin par défaut.\n"
fi
;;
g|G) if [ -f /usr/bin/simple-scan ]
then simple-scan
else echo -e "\nsimple-scan n'est pas installé. L'installer ? (O/n)"
read -n1 -p ">" scinst
if [ -z $scinst ]; then scinst=o; fi
echo
if [ "$scinst" = "o" -o "$scinst" = "O" ]
then if [ -f /usr/bin/apt ]; then sudo apt update && sudo apt install simple-scan -y; fi
if [ -f /usr/bin/pacman ]; then sudo pacman -Sy simple-scan; fi
if [ ! -f /usr/bin/apt -a ! -f /usr/bin/pacman ]; then echo -e "\nAucun gestionnaire de paquet pris en charge (apt/pacman)\n" && sleep 3; fi
fi
fi
;;
i|I) echo;break
;;
*)
echo "MAUVAIS CHOIX !"
;;
esac
done
# Particulier
while true; do
clear
echo "Type=$type";echo
echo "# Partenaire ?";echo
echo " 1) AVA-IPS"
echo " 2) BA2I"
echo " 3) BugBusters"
echo " 4) iTEC"
echo " 5) JBS"
echo " 6) Prestinfo"
echo " 7) VTI"
echo " 8) Autre"
if [ ! -z ${part} ]; then echo " i) Idem précédent ($part)"; fi;echo
read -n1 -p ">" npart
case $npart in
1) part=AVA-IPS;break
;;
2) part=BA2I;break
;;
3) part=BugBusters;break
;;
4) part=iTEC;break
;;
5) part=JBS;break
;;
6) part=Prestinfo;break
;;
7) part=VTI;break
;;
8) read -p "Partenaire=" part;break
;;
i|I) echo;break
;;
*)
echo "MAUVAIS CHOIX !"
;;
esac
done
# Date
while true; do
clear
echo "Type=$type | Partenaire=$part";echo
echo "# Date ?";echo
echo " 1) Aujourd'hui (`date +%d/%m/%y`)"
echo " 2) Hier (`date -d "yesterday 13:00" '+%d/%m/%y'`)"
echo " 3) Autre"
if [ ! -z ${date} ]; then echo " i) Idem précédent ($date)"; fi
read -n1 -p ">" ndate
case $ndate in
1) date=`date +%y%m%d`;break
;;
2) date=`date -d "yesterday 13:00" '+%y%m%d'`;break
;;
3) echo; read -p "Date(DDMMYY)=" tmpdate
date=${tmpdate:4:2}${tmpdate:2:2}${tmpdate:0:2}
break
;;
i|I) echo;break
;;
*)
echo "MAUVAIS CHOIX !"
;;
esac
done
# Lieu
while true; do
clear
echo "Type=$type | Partenaire=$part | Date=$date";echo
echo "# Lieu ?";echo
echo " 1) Gap"
echo " 2) Chorges"
echo " 3) Embrun"
echo " 4) Laragne"
echo " 5) Serres"
echo " 6) Autre"
if [ ! -z ${lieu} ]; then echo " i) Idem précédent ($lieu)"; fi
read -n1 -p ">" nlieu
case $nlieu in
1) lieu=Gap;break
;;
2) lieu=Chorges;break
;;
3) lieu=Embrun;break
;;
4) lieu=Laragne;break
;;
5) lieu=Serres;break
;;
6) read -p "Lieu=" lieu;break
;;
i|I) echo;break
;;
*)
echo "MAUVAIS CHOIX !"
;;
esac
done
# Numero intervention
clear
echo "Type=$type | Partenaire=$part | Date=$date | Lieu=$lieu";echo
if [ ! -z ${num} ]; then echo "Précédente intervention scannée : ${num} (i)"; fi
read -p "Numéro intervention=" chnum
if [ "$chnum" != "i" -a "$chnum" != "I" ]; then num=$chnum; fi
# Préparation des variables et des dossiers
rep1=20`echo ${date:0:2}-${date:2:2}`
date2=`echo ${date:0:2}-${date:2:2}-${date:4:2}`
rep2="${date2}_${lieu}"
filename="${date2}_${lieu}_${num}-${type}"
path="${defpath}/${part}/${rep1}/${rep2}"
if [ -f "${path}/${filename}.jpg" ]
then
echo -e "\nLe fichier de destination existe déjà. Que faire ?"
echo " E) Écraser"
echo " I) Incrémenter"
echo " A) Annuler"
echo
read -n1 -p "> " chex
case $chex in
e|E|é|É) echo;;
i|I) count=2 # OK
while :; do
if [ -f "${path}/${filename}${count}.jpg" ]
then ((count++))
else
break
fi
done
;;
esac
else
count=
fi
if [ ! -d "$path" ]; then mkdir -p "$path"; fi
# SCAN !
clear
echo "Type=$type$count | Partenaire=$part | Date=$date | Lieu=$lieu | Num inter=$num";echo
echo;echo Lancer le scan en appuyant sur une touche...
read
# Détection auto du scannerid
scannerid=$(scanimage -L | grep device | cut -d\` -f2 | cut -d\' -f1)
# Détection manuelle du scannerid
# lancer `scanimage -L` pour trouver "l'adresse sane" du scanner
# commenter la ligne de la détection auto, et décommenter celle ci-dessous
# scannerid=xxxxx:libusb:xxx:xxx
scanimage -d $scannerid --format jpeg --resolution 300 --mode Color >${path}/${filename}${count}.jpg && echo -e "\n${path}/${filename}.jpg scanné !\n" &
done