From 35a593e4d6d07f0134a5a42468586fb892497aa3 Mon Sep 17 00:00:00 2001 From: Adrien Beudin Date: Mon, 13 May 2013 11:14:15 +0200 Subject: [PATCH] update script --- debconf => debconfv1 | 0 debconfv2 | 1 - install_yunohost => install_yunohostv1 | 67 +++-------- install_yunohostv2 | 160 +++++++++++++++++++++++++ 4 files changed, 177 insertions(+), 51 deletions(-) rename debconf => debconfv1 (100%) rename install_yunohost => install_yunohostv1 (69%) create mode 100644 install_yunohostv2 diff --git a/debconf b/debconfv1 similarity index 100% rename from debconf rename to debconfv1 diff --git a/debconfv2 b/debconfv2 index e099932..efda977 100644 --- a/debconfv2 +++ b/debconfv2 @@ -18,4 +18,3 @@ proftpd-basic shared/proftpd/inetd_or_standalone select standalone iptables-persistent iptables-persistent/autosave_v6 boolean false iptables-persistent iptables-persistent/autosave_v4 boolean false libnss-ldapd libnss-ldapd/nsswitch multiselect group, passwd, shadow - diff --git a/install_yunohost b/install_yunohostv1 similarity index 69% rename from install_yunohost rename to install_yunohostv1 index dd64d93..72aa5ab 100755 --- a/install_yunohost +++ b/install_yunohostv1 @@ -61,7 +61,6 @@ samba=no slapd=no ssh=yes mysql=no -prosody=no EOF fi @@ -74,11 +73,11 @@ then exit $ERR_IMPOSSIBLE fi -whiptail --title "Yunohost Domain" --yesno "Your domain is $DOMAIN\nDo you want to change this?" 8 78 +whiptail --title "Yunohost Installation" --yesno "Your domain is $DOMAIN\nDo you want to change this?" 8 78 YESNO=$? case $YESNO in - 0) DOMAIN=$(whiptail --inputbox "Enter your new domain please" 8 78 --title "Yunohost Domain" 3>&1 1>&2 2>&3);; # + 0) DOMAIN=$(whiptail --inputbox "Enter your new domain please" 8 78 --title "Yunohost Installation" 3>&1 1>&2 2>&3);; # 1) ;; # => Noting to do here. Just keeping it for the record *) echo >&2 "ERROR: Unknown error ($YESNO) occured. Exiting"; exit $YESNO;; # ERROR esac @@ -118,51 +117,29 @@ EOF fi echo "======== Adding repositories ========" - #Get gpg key - wget -O- http://lemonldap-ng.org/_media/rpm-gpg-key-ow2 -q | apt-key add - -qq - wget -O- http://repo.yunohost.org/yunohost.asc -q | apt-key add - -qq - CUSTOMAPT=/etc/apt/sources.list - #if [[ "$(lsb_release -cs)" = "wheezy" ]] || [[ "$(lsb_release -cs)" = "n/a" ]] - #then - # whiptail --title "Yunohost Installation" --yesno "Caution : Yunohost v2 is in development.\nDo you want to proceed install of Yunohost?" 8 78 - # YESNO=$? - # if [[ $YESNO -eq 1 ]] - # then - # echo "======== Installation cancelled ========" - # exit $ERR_CANCEL_INSTALL - # fi - #fi - grep -qri "yunohost" $CUSTOMAPT if [[ $? -eq 1 ]] then - case "$(lsb_release -cs)" in - "squeeze") - echo "deb http://repo.yunohost.org/ squeeze main" >> $CUSTOMAPT - echo "deb http://repo.yunohost.org/ apps main" >> $CUSTOMAPT - ;; - "wheezy"|"n/a") - echo "deb http://repo.yunohost.org/ megusta main" >> $CUSTOMAPT - echo "deb http://repo.yunohost.org/ apps main" >> $CUSTOMAPT - ;; - esac + if [ "$(lsb_release -cs)" != "squeeze" ]; + then + whiptail --title "Yunohost Installation" --msgbox "Your operating system is not compatible with yunohost v1" 8 78 + exit $ERR_FAIL_INSTALL + fi fi grep -qri "lemonldap" $CUSTOMAPT if [[ $? -eq 1 ]] then - case "$(lsb_release -cs)" in - "squeeze") - echo "deb http://lemonldap-ng.org/deb squeeze main" >> $CUSTOMAPT - ;; - "wheezy"|"n/a") - echo "deb http://repo.yunohost.org/ lemonldap main" >> $CUSTOMAPT - ;; - esac + echo "deb http://lemonldap-ng.org/deb squeeze main" >> $CUSTOMAPT fi + #Get gpg key + wget -O- http://lemonldap-ng.org/_media/rpm-gpg-key-ow2 -q | apt-key add - -qq + wget -O- http://repo.yunohost.org/yunohost.asc -q | apt-key add - -qq + + #Update repo debconf-apt-progress \ --logfile /var/log/yunohost-update.log \ @@ -178,13 +155,7 @@ EOF echo "======== Install ========" #add answer in debconf db - if [[ $(lsb_release -cs) = "squeeze" ]]; - then - debconf-set-selections debconf - elif [[ $(lsb_release -cs) = "wheezy" ]] || [[ $(lsb_release -cs) = "n/a" ]]; - then - debconf-set-selections debconfv2 - fi + debconf-set-selections debconfv1 #Install yunohost packages debconf-apt-progress \ @@ -210,21 +181,17 @@ EOF service apache2 restart service dovecot restart service postfix restart - if [ "$(lsb_release -cs)" = squeeze ]; - then - service ejabberd restart - else - service prosody restart - fi + service ejabberd restart service iptables start service nscd restart service nslcd restart - echo "======== Installation success ========" + whiptail --title "Yunohost Installation" --msgbox "Installation success" 8 78 exit $SUCCESS fi else echo "======== Installation cancelled ========" + exit $ERR_CANCEL_INSTALL fi diff --git a/install_yunohostv2 b/install_yunohostv2 new file mode 100644 index 0000000..f80b709 --- /dev/null +++ b/install_yunohostv2 @@ -0,0 +1,160 @@ +#!/bin/bash + +SUCCESS=0 +ERR_FAIL_RESTORE=1 +ERR_FAIL_UPDATE=2 +ERR_FAIL_INSTALL=3 +ERR_CANCEL_INSTALL=4 +ERR_IMPOSSIBLE=-1 + +function bck { + FULLPATH="$(readlink -f "$1")" + DST="${2%/}/$(dirname $FULLPATH)" + mkdir -p "$DST" + cp -r --preserve=all "$FULLPATH" "$DST/$(basename $FULLPATH)" +} + +function rst { + [[ ! -d "$LEGACY" ]] && echo >&2 "Rollback failed : Unknown folder $LEGACY" && exit $ERR_FAIL_RESTORE + cp -rf "$LEGACY"/* / + [[ $? -ne 0 ]] && echo >&2 "Rollback failed" && exit $ERR_FAIL_RESTORE +} + +set -u +echo "======== Check rights ========" + +if [ "$(id -u)" != "0" ]; then + echo "This script must be run as root" 1>&2 + exit 1 +fi + +echo "======== YunoHost Installation ========" +echo "======== Check dependences ========" + +apt-get update -qq +for i in lsb-release wget whiptail +do + dpkg -l | grep -q $i + if [[ $? -eq 1 ]] + then + apt-get install $i -y + fi +done + +if [[ ! -f /etc/yunohost/yunohost.conf ]] +then +mkdir /etc/yunohost/ +cat << EOF > /etc/yunohost/yunohost.conf +#Yunohost custom config +#to enable yunohost custom config change no by yes + +amavis=no +apache2=no +dovecot=no +iptables=no +lemonldap-ng=no +postfix=no +proftpd=no +radicale=no +samba=no +slapd=no +ssh=yes +mysql=no +prosody=no +EOF +fi + +echo "======== Checking domain ========" +DOMAIN=$(hostname -d) +if [[ "${DOMAIN:-1}" = 1 ]] +then + echo "======== Installation failed ========" + echo "Configure your domain name please" + exit $ERR_IMPOSSIBLE +fi + +whiptail --title "Yunohost Installation" --yesno "Caution : your config files for postfix,dovecot,mysql,apache,prosody,radicale will be overwritten\nDo you want to proceed install of Yunohost?" 8 78 +YESNO=$? + +if [[ $YESNO -eq 0 ]] +then + # Backup folder for legacy config files + LEGACY=/etc/yunohost/.legacy + mkdir -p "$LEGACY" + + echo "======== Adding repositories ========" + + CUSTOMAPT=/etc/apt/sources.list + + grep -qri "yunohost" $CUSTOMAPT + if [[ $? -eq 1 ]] + then + echo "deb http://repo.yunohost.org/ megusta main" >> $CUSTOMAPT + fi + + grep -qri "lemonldap" $CUSTOMAP + if [[ $? -eq 1 ]] + then + echo "deb http://repo.yunohost.org/ lemonldap main" >> $CUSTOMAPT + fi + + #Get gpg key + wget -O- http://lemonldap-ng.org/_media/rpm-gpg-key-ow2 -q | apt-key add - -qq + wget -O- http://repo.yunohost.org/yunohost.asc -q | apt-key add - -qq + + #Update repo + debconf-apt-progress \ + --logfile /var/log/yunohost-update.log \ + -- \ + apt-get update + + if [[ $? -ne 0 ]] + then + echo "Update Repo Failure : Rolling back" + rst "$LEGACY" + exit $ERR_FAIL_UPDATE + fi + + echo "======== Install ========" + #add answer in debconf db + debconf-set-selections debconfv2 + + #Install yunohost packages + debconf-apt-progress \ + --logfile /var/log/yunohost.log \ + -- \ + apt-get -o Dpkg::Options::="--force-confold" \ + -y install \ + yunohost \ + yunohost-config \ + yunohost-config-postfix \ + postfix postfix-ldap \ + postfix-policyd-spf-perl + + if [[ $? -ne 0 ]] + then + echo "======== Installation failed ========" + echo "Rolling back have to be done manually !" + echo "Check your legacy configuration files => '$LEGACY'" + echo "Check install logs => '/var/log/yunohost.log' and '/var/log/yunohost.error'" + exit $ERR_FAIL_INSTALL + else + service slapd restart + service apache2 restart + service dovecot restart + service postfix restart + service prosody restart + service iptables start + service nscd restart + service nslcd restart + IP=$(/sbin/ifconfig | sed '/Bcast/!d' | awk '{print $2}' | sed 's/.*\://') + whiptail --title "Yunohost Installation" --msgbox "Installation success\n Connect to http://$IP:6767 for finish installation" 8 78 + fi + +else + echo "======== Installation cancelled ========" + exit $ERR_CANCEL_INSTALL +fi + +# Security : we shouldn't be able to exit here +exit $ERR_IMPOSSIBLE