Add automode, Use getopts, show usage with -h

This commit is contained in:
Julien Malik 2015-09-07 00:00:43 +02:00
parent edbde8450a
commit f796569d97

View file

@ -125,6 +125,8 @@ set_domain() {
} }
confirm_installation() { confirm_installation() {
[[ "AUTOMODE" == "1" ]] && return 0
local text=" local text="
Caution ! Caution !
@ -148,14 +150,12 @@ setup_package_source() {
echo "deb http://repo.yunohost.org/ megusta main" > $CUSTOMAPT echo "deb http://repo.yunohost.org/ megusta main" > $CUSTOMAPT
# Also add repositories for 'testing' and/or 'unstable' if the script has been called with those arguments # Also add repositories for 'testing' and/or 'unstable' if the script has been called with those arguments
if [[ "$#" -gt "0" ]]; then if [[ "$DISTRIB" == "test" ]] || [[ "$DISTRIB" == "testing" ]] ; then
if [[ "$1" == "test" ]] || [[ "$1" == "testing" ]] ; then echo "deb http://repo.yunohost.org/ testing main" >> $CUSTOMAPT
echo "deb http://repo.yunohost.org/ testing main" >> $CUSTOMAPT fi
fi if [[ "$DISTRIB" == "daily" ]] || [[ "$DISTRIB" == "unstable" ]] ; then
if [[ "$1" == "daily" ]] || [[ "$1" == "unstable" ]] ; then echo "deb http://repo.yunohost.org/ testing main" >> $CUSTOMAPT
echo "deb http://repo.yunohost.org/ testing main" >> $CUSTOMAPT echo "deb http://repo.yunohost.org/ unstable main" >> $CUSTOMAPT
echo "deb http://repo.yunohost.org/ unstable main" >> $CUSTOMAPT
fi
fi fi
# Add YunoHost repository key to the keyring # Add YunoHost repository key to the keyring
@ -271,6 +271,9 @@ restart_services() {
} }
post_install() { post_install() {
# No postinstall in auto mode
[[ "AUTOMODE" == "1" ]] && return 0
# Remove whiptail and dialog remains... # Remove whiptail and dialog remains...
clear clear
@ -314,11 +317,50 @@ Do you want to try again now?
return 0 return 0
} }
usage() {
print "
Usage `basename $0` [-a] [-d <DISTRIB>] [-h]
Options :
-a Enable automatic mode. No questions are asked.
This does not do the post-install step.
-d Choose the distribution to install ('stable', 'testing', 'unstable').
Defaults to 'stable'
-h Prints this help
"
}
# Treat unset variables as an error when performing # Treat unset variables as an error when performing
# parameter expansion. An error message will be written # parameter expansion. An error message will be written
# to the standard error, and a non-interactive shell will exit. # to the standard error, and a non-interactive shell will exit.
set -u set -u
AUTOMODE=0
DISTRIB=stable
while getopts ":ad:h" option; do
case $option in
a)
AUTOMODE=1
export DEBIAN_FRONTEND=noninteractive
;;
d)
DISTRIB=$OPTARG
;;
h)
usage
exit 0
;;
:)
usage
exit 1
;;
\?)
usage
exit 1
;;
esac
done
if ! ensure_root ; then if ! ensure_root ; then
die "This script must be run as root" 1 die "This script must be run as root" 1
fi fi