# détection des "Ctrl+C"
trap cancelScript INT
function cancelScript() {
echo
echo "CTRL-C Détecté."
echo "Sortie."
set +o posix
exit 1
}
apt-check () {
# detect if packages are installed
installedPackages=$(dpkg-query -W --showformat='${Status}\n' $@ 2>&1 | uniq)
if [ "install ok installed" != "$installedPackages" ]; then
terminal-switch-second
echo
echo "Le(s) packet(s) (\"$@\") doivent être installés"
echo
echo -e "\e[2msudo apt-get install $@\e[0m"
echo
read -p 'Continuer ? (o/n): ' reply;
case $reply in
o|O|y|Y )
# Because we said 'yes' I put -y to proceed with installation
# without additional question 'yes/no' from apt-get
sudo apt-get -y install "$@" || {
echo
echo -e "\033[1;31m ERREUR d'installation ! Contactez un administrateur.\033[0m"
echo
echo -e "vous pouvez tenter d'executer : \e[2msudo add-apt-repository universe\e[0m"
echo "et relancez ce script"
echo
exit 1;
}
;;
*)
# For any other answer, we just do nothing. That means we do not install
# listed packages.
echo "Annulation de l'installation"
exit 1
;;
esac
fi
terminal-switch-first
}
# save current terminal cursor position
terminal-save() {
tput sc
}
# restore terminal cursor position and clean after position
terminal-restore() {
tput rc
tput ed
}
# save all current terminal screen
terminal-switch-second() {
tput smcup
clear
}
# restore all terminal screen
terminal-switch-first() {
tput rmcup
}