mirror of
https://github.com/YunoHost/install_script.git
synced 2024-09-03 20:06:25 +02:00
commit
c2dbb333ae
8 changed files with 407 additions and 609 deletions
50
README.md
50
README.md
|
@ -1,42 +1,44 @@
|
|||
# Script
|
||||
# YunoHost installation scripts
|
||||
|
||||
## Prérequis
|
||||
## Context
|
||||
|
||||
Afin de pouvoir récupérer le script install_yunohost, il faut avoir git d'installé sur votre machine.
|
||||
The scripts in this repository will install [YunoHost](https://yunohost.org/) on a Debian system.
|
||||
|
||||
Pour l'installer sur une distribution Debian:
|
||||
Only Debian 7 (aka wheezy) and 8 (aka jessie) are supported.
|
||||
|
||||
# apt-get install git
|
||||
## Basic usage
|
||||
|
||||
ou
|
||||
|
||||
$ sudo apt-get install git
|
||||
|
||||
## Récuperation du script
|
||||
|
||||
Placez vous tout d'abord dans le répertoire /tmp:
|
||||
Go into a temporary folder, e.g. ```/tmp```:
|
||||
|
||||
$ cd /tmp
|
||||
|
||||
Récupérez le script grâce à git:
|
||||
Get the install script:
|
||||
|
||||
$ git clone https://github.com/YunoHost/install_script.git
|
||||
$ wget https://raw.githubusercontent.com/YunoHost/install_script/master/install_yunohostv2
|
||||
|
||||
Déplacez vous dans le répertoire Script nouvellement cloné:
|
||||
Execute the script:
|
||||
|
||||
$ cd install_script/
|
||||
$ bash install_yunohostv2
|
||||
|
||||
Rendez le script install_yunohost exécutable:
|
||||
If something goes wrong, you can check the installation logs saved in ```/var/log/yunohost.log```
|
||||
|
||||
$ chmod o+x install_yunohost
|
||||
## Advanced usage
|
||||
|
||||
Exécutez le script:
|
||||
The script supports a number of positional arguments:
|
||||
|
||||
$ ./install_yunohostv1
|
||||
$ bash install_yunohostv2 -h
|
||||
Usage :
|
||||
install_yunohostv2 [-a] [-d <DISTRIB>] [-h]
|
||||
|
||||
ou
|
||||
Options :
|
||||
-a Enable automatic mode. No questions are asked.
|
||||
This does not perform the post-install step.
|
||||
-d Choose the distribution to install ('stable', 'testing', 'unstable').
|
||||
Defaults to 'stable'
|
||||
-h Prints this help and exit
|
||||
|
||||
$ ./install_yunohostv2
|
||||
By specifying ```-a```, the installation will be performed without asking any question.
|
||||
This is useful for fully automated headless installations.
|
||||
The [post-installation](https://yunohost.org/#/postinstall) will need to be performed later.
|
||||
|
||||
|
||||
Le script va automatiquement lancer l'installation de yunohost sur votre poste ainsi que tous les paquets nécessaires. Répondez simplement aux questions qui vous seront posées.
|
||||
The ```-d <DISTRIB>``` switch is mostly for advanced users who want to install the bleeding edge versions of YunoHost packages.
|
||||
|
|
|
@ -1,174 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
SUCCESS=0
|
||||
ERR_FAIL_RESTORE=1
|
||||
ERR_FAIL_UPDATE=2
|
||||
ERR_FAIL_INSTALL=3
|
||||
ERR_CANCEL_INSTALL=4
|
||||
ERR_IMPOSSIBLE=-1
|
||||
NO_ERR=0
|
||||
|
||||
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
|
||||
|
||||
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
SOURCE="$(readlink "$SOURCE")"
|
||||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
||||
done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
|
||||
echo "Running from $DIR"
|
||||
|
||||
echo "Check dependencies"
|
||||
|
||||
apt-get update -qq
|
||||
for i in lsb-release wget dialog whiptail
|
||||
do
|
||||
dpkg -l | grep -q $i
|
||||
if [[ $? -eq 1 ]]
|
||||
then
|
||||
apt-get install $i -y
|
||||
fi
|
||||
done
|
||||
|
||||
# Fix install on jessie
|
||||
if [ $(lsb_release -c | awk '{print $2}') = jessie ];
|
||||
then
|
||||
apt-get install python-xmpp -y
|
||||
fi
|
||||
|
||||
if [[ ! -f /etc/yunohost/yunohost.conf ]]
|
||||
then
|
||||
mkdir /etc/yunohost/
|
||||
touch /etc/yunohost/from_script
|
||||
cat << EOF > /etc/yunohost/yunohost.conf
|
||||
# Yunohost custom config
|
||||
# If you want to keep a custom service configuration replace "no" by "yes"
|
||||
# for the concerned service
|
||||
|
||||
amavis=no
|
||||
avahi=no
|
||||
dovecot=no
|
||||
iptables=no
|
||||
metronome=no
|
||||
mysql=no
|
||||
nginx=no
|
||||
postfix=no
|
||||
samba=no
|
||||
slapd=no
|
||||
ssh=yes
|
||||
ssowat=no
|
||||
EOF
|
||||
fi
|
||||
|
||||
echo "Checking domain"
|
||||
DOMAIN=$(hostname -d)
|
||||
if [[ "${DOMAIN:-1}" = 1 ]]
|
||||
then
|
||||
hostname yunohost.yunohost.org
|
||||
DOMAIN='yunohost.org'
|
||||
fi
|
||||
|
||||
YESNO=0
|
||||
|
||||
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
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
if [[ "$1" == "test" ]] || [[ "$1" == "testing" ]] ; then
|
||||
echo "deb http://daily.yunohost.org/ testing main" >> $CUSTOMAPT
|
||||
fi
|
||||
if [[ "$1" == "daily" ]] || [[ "$1" == "unstable" ]] ; then
|
||||
echo "deb http://daily.yunohost.org/ testing main" >> $CUSTOMAPT
|
||||
echo "deb http://daily.yunohost.org/ unstable main" >> $CUSTOMAPT
|
||||
fi
|
||||
fi
|
||||
|
||||
#Get gpg key
|
||||
wget -O- http://repo.yunohost.org/yunohost.asc -q | apt-key add - -qq
|
||||
|
||||
#Update repo
|
||||
apt-get update -qq
|
||||
|
||||
if [[ $? -ne 0 ]]
|
||||
then
|
||||
echo "Update Repo Failure : Rolling back"
|
||||
rst "$LEGACY"
|
||||
exit $ERR_FAIL_UPDATE
|
||||
fi
|
||||
|
||||
chmod 755 / *
|
||||
|
||||
echo "Installation"
|
||||
#add answer in debconf db
|
||||
if [ $(lsb_release -c | awk '{print $2}') = jessie ];
|
||||
then
|
||||
debconf-set-selections $DIR/debconfjessie
|
||||
else
|
||||
debconf-set-selections $DIR/debconfv2
|
||||
fi
|
||||
|
||||
#Install yunohost packages
|
||||
apt-get -o Dpkg::Options::="--force-confold" \
|
||||
-y install \
|
||||
-qq \
|
||||
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
|
||||
|
||||
echo -e "\n"
|
||||
fi
|
||||
|
||||
else
|
||||
echo "Installation cancelled"
|
||||
exit $ERR_CANCEL_INSTALL
|
||||
fi
|
||||
|
||||
# Security : we shouldn't be able to exit here
|
||||
exit $NO_ERR
|
|
@ -1,18 +0,0 @@
|
|||
slapd slapd/password1 password yunohost
|
||||
slapd slapd/password2 password yunohost
|
||||
slapd slapd/domain string yunohost.org
|
||||
slapd shared/organization string yunohost.org
|
||||
slapd slapd/allow_ldap_v2 boolean false
|
||||
slapd slapd/invalid_config boolean true
|
||||
slapd slapd/backend select MDB
|
||||
postfix postfix/main_mailer_type select Internet Site
|
||||
postfix postfix/mailname string /etc/mailname
|
||||
mysql-server-5.5 mysql-server/root_password password yunohost
|
||||
mysql-server-5.5 mysql-server/root_password_again password yunohost
|
||||
nslcd nslcd/ldap-bindpw password
|
||||
nslcd nslcd/ldap-starttls boolean false
|
||||
nslcd nslcd/ldap-reqcert select
|
||||
nslcd nslcd/ldap-uris string ldap://localhost/
|
||||
nslcd nslcd/ldap-binddn string
|
||||
nslcd nslcd/ldap-base string dc=yunohost,dc=org
|
||||
libnss-ldapd libnss-ldapd/nsswitch multiselect group, passwd, shadow
|
14
debconfv1
14
debconfv1
|
@ -1,14 +0,0 @@
|
|||
postfix postfix/main_mailer_type select Internet Site
|
||||
postfix postfix/mailname string /etc/mailname
|
||||
mysql-server-5.1 mysql-server/root_password password yunohost
|
||||
mysql-server-5.1 mysql-server/root_password_again password yunohost
|
||||
samba-common samba-common/workgroup string WORKGROUP
|
||||
samba-common samba-common/workgroup boolean true
|
||||
nslcd nslcd/ldap-bindpw password
|
||||
nslcd nslcd/ldap-starttls boolean false
|
||||
nslcd nslcd/ldap-reqcert select
|
||||
nslcd nslcd/ldap-uris string ldap://localhost/
|
||||
nslcd nslcd/ldap-binddn string
|
||||
nslcd nslcd/ldap-base string dc=yunohost,dc=org
|
||||
proftpd-basic shared/proftpd/inetd_or_standalone select standalone
|
||||
libnss-ldapd libnss-ldapd/nsswitch multiselect group, passwd, shadow
|
15
debconfv2
15
debconfv2
|
@ -1,15 +0,0 @@
|
|||
slapd slapd/password1 password yunohost
|
||||
slapd slapd/password2 password yunohost
|
||||
slapd slapd/domain string yunohost.org
|
||||
slapd shared/organization string yunohost.org
|
||||
postfix postfix/main_mailer_type select Internet Site
|
||||
postfix postfix/mailname string /etc/mailname
|
||||
mysql-server-5.5 mysql-server/root_password password yunohost
|
||||
mysql-server-5.5 mysql-server/root_password_again password yunohost
|
||||
nslcd nslcd/ldap-bindpw password
|
||||
nslcd nslcd/ldap-starttls boolean false
|
||||
nslcd nslcd/ldap-reqcert select
|
||||
nslcd nslcd/ldap-uris string ldap://localhost/
|
||||
nslcd nslcd/ldap-binddn string
|
||||
nslcd nslcd/ldap-base string dc=yunohost,dc=org
|
||||
libnss-ldapd libnss-ldapd/nsswitch multiselect group, passwd, shadow
|
1
install_yunohost
Symbolic link
1
install_yunohost
Symbolic link
|
@ -0,0 +1 @@
|
|||
install_yunohostv2
|
|
@ -1,199 +0,0 @@
|
|||
#!/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
|
||||
ejabberd=no
|
||||
iptables=no
|
||||
lemonldap-ng=no
|
||||
postfix=no
|
||||
proftpd=no
|
||||
radicale=no
|
||||
samba=no
|
||||
slapd=no
|
||||
ssh=yes
|
||||
mysql=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 "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 Installation" 3>&1 1>&2 2>&3);; # <YES>
|
||||
1) ;; # <NO> => Noting to do here. Just keeping it for the record
|
||||
*) echo >&2 "ERROR: Unknown error ($YESNO) occured. Exiting"; exit $YESNO;; # ERROR
|
||||
esac
|
||||
|
||||
[[ -z "$DOMAIN" ]] && DOMAIN="$(hostname -d)"
|
||||
|
||||
whiptail --title "Yunohost Installation" --yesno "Caution : your config files for postfix,dovecot,mysql,apache,ejabberd,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 "======== Updating hostname ========"
|
||||
# Update hostname
|
||||
bck /etc/hostname "$LEGACY"
|
||||
echo "yunohost" > /etc/hostname
|
||||
# Update hosts
|
||||
if [[ $(grep -c "yunohost.$DOMAIN" /etc/hosts) -eq 0 ]]
|
||||
then
|
||||
bck /etc/hosts "$LEGACY"
|
||||
cat <<EOF > /etc/hosts
|
||||
127.0.0.1 localhost
|
||||
127.0.1.1 yunohost.$DOMAIN yunohost
|
||||
|
||||
# The following lines are desirable for IPv6 capable hosts
|
||||
::1 ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
EOF
|
||||
echo -e "127.0.0.1\tyunohost.$DOMAIN\tyunohost" > /etc/hosts
|
||||
/etc/init.d/hostname.sh start
|
||||
fi
|
||||
|
||||
echo "======== Adding repositories ========"
|
||||
CUSTOMAPT=/etc/apt/sources.list
|
||||
|
||||
grep -qri "yunohost" $CUSTOMAPT
|
||||
if [[ $? -eq 1 ]]
|
||||
then
|
||||
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
|
||||
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 \
|
||||
-- \
|
||||
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 debconfv1
|
||||
|
||||
#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 ejabberd restart
|
||||
service iptables start
|
||||
service nscd restart
|
||||
service nslcd restart
|
||||
whiptail --title "Yunohost Installation" --msgbox "Installation success" 8 78
|
||||
exit $SUCCESS
|
||||
fi
|
||||
|
||||
else
|
||||
echo "======== Installation cancelled ========"
|
||||
|
||||
exit $ERR_CANCEL_INSTALL
|
||||
fi
|
||||
|
||||
# Security : we shouldn't be able to exit here
|
||||
exit $ERR_IMPOSSIBLE
|
|
@ -1,71 +1,113 @@
|
|||
#!/bin/bash
|
||||
|
||||
SUCCESS=0
|
||||
ERR_FAIL_RESTORE=1
|
||||
ERR_FAIL_UPDATE=2
|
||||
ERR_FAIL_INSTALL=3
|
||||
ERR_CANCEL_INSTALL=4
|
||||
ERR_IMPOSSIBLE=-1
|
||||
# Copyright (C) 2015 kload, beudbeud
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
function bck {
|
||||
FULLPATH="$(readlink -f "$1")"
|
||||
DST="${2%/}/$(dirname $FULLPATH)"
|
||||
mkdir -p "$DST"
|
||||
cp -r --preserve=all "$FULLPATH" "$DST/$(basename $FULLPATH)"
|
||||
YUNOHOST_LOG="/var/log/yunohost-installation.log"
|
||||
|
||||
print() {
|
||||
printf "%s\n" "$*";
|
||||
}
|
||||
|
||||
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
|
||||
notify_about_install_logs() {
|
||||
print "
|
||||
Installation logs are located in $YUNOHOST_LOG
|
||||
" 1>&2
|
||||
|
||||
}
|
||||
|
||||
set -u
|
||||
success() {
|
||||
tput setf 2
|
||||
print "Success !"
|
||||
tput sgr 0
|
||||
notify_about_install_logs
|
||||
}
|
||||
|
||||
echo "======== Get path of current script ======="
|
||||
die() {
|
||||
# Print to log file
|
||||
print "
|
||||
Failure !
|
||||
The following error was caught during Yunohost installation :
|
||||
|
||||
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
SOURCE="$(readlink "$SOURCE")"
|
||||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
||||
done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
$1
|
||||
" >> $YUNOHOST_LOG
|
||||
|
||||
echo "Running from $DIR"
|
||||
# Print to terminal
|
||||
tput setf 4
|
||||
print "Failure !"
|
||||
tput sgr 0
|
||||
|
||||
echo "======== Check rights ========"
|
||||
print "\
|
||||
The following error was caught during YunoHost installation :
|
||||
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
echo "This script must be run as root" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
$1
|
||||
" 1>&2
|
||||
|
||||
echo "======== YunoHost Installation ========"
|
||||
echo "======== Check dependencies ========"
|
||||
notify_about_install_logs
|
||||
exit "${2:-1}"
|
||||
}
|
||||
|
||||
apt-get update -qq
|
||||
for i in lsb-release wget dialog whiptail
|
||||
do
|
||||
dpkg -l | grep -q $i
|
||||
if [[ $? -eq 1 ]]
|
||||
then
|
||||
apt-get install $i -y
|
||||
fi
|
||||
done
|
||||
step() {
|
||||
printf "[ $(date --rfc-3339=seconds) ] ----- [ entering %-30s ]\n" "$1" >> $YUNOHOST_LOG
|
||||
$*
|
||||
local return_code="$?"
|
||||
return $return_code
|
||||
}
|
||||
|
||||
# Fix install on jessie
|
||||
if [ $(lsb_release -c | awk '{print $2}') = jessie ];
|
||||
then
|
||||
apt-get install python-xmpp -y
|
||||
fi
|
||||
ensure_root() {
|
||||
if [[ "$(id -u)" != "0" ]] ;
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
if [[ ! -f /etc/yunohost/yunohost.conf ]]
|
||||
then
|
||||
mkdir /etc/yunohost/
|
||||
touch /etc/yunohost/from_script
|
||||
cat << EOF > /etc/yunohost/yunohost.conf
|
||||
apt_get_wrapper() {
|
||||
if [[ "$AUTOMODE" == "0" ]] ;
|
||||
then
|
||||
debconf-apt-progress \
|
||||
--logfile $YUNOHOST_LOG \
|
||||
-- \
|
||||
apt-get $*
|
||||
else
|
||||
apt-get $* >> $YUNOHOST_LOG 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
upgrade_system() {
|
||||
apt_get_wrapper update \
|
||||
|| return 1
|
||||
|
||||
apt_get_wrapper -y dist-upgrade \
|
||||
|| return 2
|
||||
}
|
||||
|
||||
installscript_dependencies() {
|
||||
# install dependencies of the install script itself
|
||||
apt_get_wrapper -o Dpkg::Options::="--force-confold" \
|
||||
-y --force-yes install \
|
||||
lsb-release wget whiptail \
|
||||
|| return 1
|
||||
}
|
||||
|
||||
create_custom_config() {
|
||||
if [[ ! -f /etc/yunohost/yunohost.conf ]]
|
||||
then
|
||||
mkdir /etc/yunohost/
|
||||
touch /etc/yunohost/from_script
|
||||
cat << EOF > /etc/yunohost/yunohost.conf
|
||||
# Yunohost custom config
|
||||
# If you want to keep a custom service configuration replace "no" by "yes"
|
||||
# for the concerned service
|
||||
|
@ -83,122 +125,295 @@ slapd=no
|
|||
ssh=yes
|
||||
ssowat=no
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
confirm_installation() {
|
||||
[[ "$AUTOMODE" == "1" ]] && return 0
|
||||
|
||||
local text="
|
||||
Caution !
|
||||
|
||||
Your configuration files for :
|
||||
- postfix
|
||||
- dovecot
|
||||
- mysql
|
||||
- nginx
|
||||
- metronome
|
||||
will be overwritten !
|
||||
|
||||
Are you sure you want to proceed with the installation of Yunohost?
|
||||
"
|
||||
whiptail --title "Yunohost Installation" --yesno "$text" 20 78
|
||||
}
|
||||
|
||||
setup_package_source() {
|
||||
local CUSTOMAPT=/etc/apt/sources.list.d/yunohost.list
|
||||
|
||||
# In any case we need the main stable repo
|
||||
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
|
||||
if [[ "$DISTRIB" == "test" ]] || [[ "$DISTRIB" == "testing" ]] ; then
|
||||
echo "deb http://repo.yunohost.org/ testing main" >> $CUSTOMAPT
|
||||
fi
|
||||
if [[ "$DISTRIB" == "daily" ]] || [[ "$DISTRIB" == "unstable" ]] ; then
|
||||
echo "deb http://repo.yunohost.org/ testing main" >> $CUSTOMAPT
|
||||
echo "deb http://repo.yunohost.org/ unstable main" >> $CUSTOMAPT
|
||||
fi
|
||||
|
||||
# Add YunoHost repository key to the keyring
|
||||
wget -O- http://repo.yunohost.org/yunohost.asc -q | apt-key add - -qq > /dev/null
|
||||
}
|
||||
|
||||
apt_update() {
|
||||
apt_get_wrapper update
|
||||
}
|
||||
|
||||
register_debconf() {
|
||||
if [[ $(lsb_release -c | awk '{print $2}') == jessie ]];
|
||||
then
|
||||
debconf-set-selections << EOF
|
||||
slapd slapd/password1 password yunohost
|
||||
slapd slapd/password2 password yunohost
|
||||
slapd slapd/domain string yunohost.org
|
||||
slapd shared/organization string yunohost.org
|
||||
slapd slapd/allow_ldap_v2 boolean false
|
||||
slapd slapd/invalid_config boolean true
|
||||
slapd slapd/backend select MDB
|
||||
postfix postfix/main_mailer_type select Internet Site
|
||||
postfix postfix/mailname string /etc/mailname
|
||||
mysql-server-5.5 mysql-server/root_password password yunohost
|
||||
mysql-server-5.5 mysql-server/root_password_again password yunohost
|
||||
nslcd nslcd/ldap-bindpw password
|
||||
nslcd nslcd/ldap-starttls boolean false
|
||||
nslcd nslcd/ldap-reqcert select
|
||||
nslcd nslcd/ldap-uris string ldap://localhost/
|
||||
nslcd nslcd/ldap-binddn string
|
||||
nslcd nslcd/ldap-base string dc=yunohost,dc=org
|
||||
libnss-ldapd libnss-ldapd/nsswitch multiselect group, passwd, shadow
|
||||
EOF
|
||||
else
|
||||
debconf-set-selections << EOF
|
||||
slapd slapd/password1 password yunohost
|
||||
slapd slapd/password2 password yunohost
|
||||
slapd slapd/domain string yunohost.org
|
||||
slapd shared/organization string yunohost.org
|
||||
postfix postfix/main_mailer_type select Internet Site
|
||||
postfix postfix/mailname string /etc/mailname
|
||||
mysql-server-5.5 mysql-server/root_password password yunohost
|
||||
mysql-server-5.5 mysql-server/root_password_again password yunohost
|
||||
nslcd nslcd/ldap-bindpw password
|
||||
nslcd nslcd/ldap-starttls boolean false
|
||||
nslcd nslcd/ldap-reqcert select
|
||||
nslcd nslcd/ldap-uris string ldap://localhost/
|
||||
nslcd nslcd/ldap-binddn string
|
||||
nslcd nslcd/ldap-base string dc=yunohost,dc=org
|
||||
libnss-ldapd libnss-ldapd/nsswitch multiselect group, passwd, shadow
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
workaround_avahi_installation() {
|
||||
|
||||
# When attempting several installation of Yunohost on the same host
|
||||
# with a light VM system like LXC
|
||||
# we hit a bug with avahi-daemon postinstallation
|
||||
# This is described in detail in https://github.com/lxc/lxc/issues/25
|
||||
#
|
||||
# It makes the configure step of avahi-daemon fail, because the service does
|
||||
# start correctly. Then all other packages depending on avahi-daemon refuse to
|
||||
# configure themselves.
|
||||
#
|
||||
# The workaround we use is to generate a random uid for the avahi user, and
|
||||
# create the user with this id beforehand, so that the avahi-daemon postinst
|
||||
# script does not do it on its own. Our randomized uid has far less chances to
|
||||
# be already in use in another system than the automated one (which tries to use
|
||||
# consecutive uids).
|
||||
|
||||
# Return without error if avahi already exists
|
||||
if id avahi > /dev/null 2>&1 ; then
|
||||
print "User avahi already exists (with uid $(id avahi)), skipping avahi workaround" >> $YUNOHOST_LOG
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Get a random unused uid between 500 and 999 (system-user)
|
||||
local avahi_id=$((500 + RANDOM % 500))
|
||||
while cut -d ':' -f 3 /etc/passwd | grep -q $avahi_id ;
|
||||
do
|
||||
avahi_id=$((500 + RANDOM % 500))
|
||||
done
|
||||
|
||||
print "Workaround for avahi : creating avahi user with uid $avahi_id" >> $YUNOHOST_LOG
|
||||
|
||||
# Use the same adduser parameter as in the avahi-daemon postinst script
|
||||
# Just specify --uid explicitely
|
||||
adduser --disabled-password --quiet --system \
|
||||
--home /var/run/avahi-daemon --no-create-home \
|
||||
--gecos "Avahi mDNS daemon" --group avahi \
|
||||
--uid $avahi_id
|
||||
}
|
||||
|
||||
install_yunohost_packages() {
|
||||
apt_get_wrapper \
|
||||
-o Dpkg::Options::="--force-confold" \
|
||||
-y --force-yes install \
|
||||
yunohost yunohost-config \
|
||||
yunohost-config-postfix \
|
||||
postfix postfix-ldap \
|
||||
postfix-policyd-spf-perl
|
||||
}
|
||||
|
||||
restart_services() {
|
||||
service slapd restart
|
||||
# service yunohost-firewall start
|
||||
service nscd restart
|
||||
service nslcd restart
|
||||
|
||||
# NOTE : We don't fail if slapd fails to restart...
|
||||
return 0
|
||||
}
|
||||
|
||||
post_install() {
|
||||
# No postinstall in auto mode
|
||||
[[ "$AUTOMODE" == "1" ]] && return 0
|
||||
|
||||
# Remove whiptail and dialog remains...
|
||||
clear
|
||||
|
||||
local text="
|
||||
Yunohost packages have been installed successfully!
|
||||
|
||||
You can now proceed with Yunohost post-installation.
|
||||
This is where you will be asked for :
|
||||
- the main DNS domain name of your server
|
||||
- the administration password
|
||||
|
||||
You can also perform this step later on your own :
|
||||
- either from a shell, by running 'yunohost tools postinstall'
|
||||
as root
|
||||
- either from your web browser, by accessing https://yunohost.local
|
||||
|
||||
Please refer to https://yunohost.org/#/postinstall
|
||||
for additionnal information.
|
||||
|
||||
Do you want to proceed with YunoHost post-installation now?
|
||||
"
|
||||
whiptail --title "Post-installation" --yesno "$text" 25 78 \
|
||||
|| return 0
|
||||
|
||||
/usr/bin/yunohost tools postinstall
|
||||
|
||||
local POSTINSTALL_EXIT_CODE="$?"
|
||||
while [[ "$POSTINSTALL_EXIT_CODE" != "0" ]] ;
|
||||
do
|
||||
local text_retry="
|
||||
Yunohost post-installation has failed.
|
||||
|
||||
Do you want to try again now?
|
||||
"
|
||||
whiptail --title "Post-installation" --yesno "$text_retry" 12 78 --defaultno \
|
||||
|| return $POSTINSTALL_EXIT_CODE
|
||||
|
||||
/usr/bin/yunohost tools postinstall
|
||||
POSTINSTALL_EXIT_CODE="$?"
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
usage() {
|
||||
print "
|
||||
Usage :
|
||||
`basename $0` [-a] [-d <DISTRIB>] [-h]
|
||||
|
||||
Options :
|
||||
-a Enable automatic mode. No questions are asked.
|
||||
This does not perform the post-install step.
|
||||
-d Choose the distribution to install ('stable', 'testing', 'unstable').
|
||||
Defaults to 'stable'
|
||||
-h Prints this help and exit
|
||||
"
|
||||
}
|
||||
|
||||
# Treat unset variables as an error when performing
|
||||
# parameter expansion. An error message will be written
|
||||
# to the standard error, and a non-interactive shell will exit.
|
||||
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 ! step ensure_root ; then
|
||||
die "This script must be run as root" 1
|
||||
fi
|
||||
|
||||
echo "======== Checking domain ========"
|
||||
DOMAIN=$(hostname -d)
|
||||
if [[ "${DOMAIN:-1}" = 1 ]]
|
||||
then
|
||||
hostname yunohost.yunohost.org
|
||||
DOMAIN='yunohost.org'
|
||||
if ! step upgrade_system ; then
|
||||
die "Unable to update the system" 2
|
||||
fi
|
||||
|
||||
whiptail --title "Yunohost Installation" --yesno "Caution : your config files for postfix,dovecot,mysql,nginx,metronome 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
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
if [[ "$1" == "test" ]] || [[ "$1" == "testing" ]] ; then
|
||||
echo "deb http://daily.yunohost.org/ testing main" >> $CUSTOMAPT
|
||||
fi
|
||||
if [[ "$1" == "daily" ]] || [[ "$1" == "unstable" ]] ; then
|
||||
echo "deb http://daily.yunohost.org/ testing main" >> $CUSTOMAPT
|
||||
echo "deb http://daily.yunohost.org/ unstable main" >> $CUSTOMAPT
|
||||
fi
|
||||
fi
|
||||
|
||||
#Get gpg key
|
||||
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
|
||||
if [ $(lsb_release -c | awk '{print $2}') = jessie ];
|
||||
then
|
||||
debconf-set-selections $DIR/debconfjessie
|
||||
else
|
||||
debconf-set-selections $DIR/debconfv2
|
||||
fi
|
||||
|
||||
#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
|
||||
if [ -f /etc/init.d/yunohost-firewall ];
|
||||
then
|
||||
service yunohost-firewall start
|
||||
fi
|
||||
service nscd restart
|
||||
service nslcd restart
|
||||
|
||||
echo -e "\n"
|
||||
whiptail --title "Post-installation" --yesno "Proceed to post-installation?" 8 78
|
||||
YESNO=$?
|
||||
RESULT=1
|
||||
while [ $RESULT -gt 0 ]; do
|
||||
if [[ $YESNO -eq 0 ]]; then
|
||||
echo -e "\n"
|
||||
/usr/bin/yunohost tools postinstall
|
||||
let RESULT=$?
|
||||
if [ $RESULT -gt 0 ]; then
|
||||
echo -e "\n"
|
||||
whiptail --title "Post-installation" --yesno "Post-installation failed, retry ?" 8 78
|
||||
let YESNO=$?
|
||||
fi
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
else
|
||||
echo "======== Installation cancelled ========"
|
||||
exit $ERR_CANCEL_INSTALL
|
||||
if ! step installscript_dependencies ; then
|
||||
die "Unable to install dependencies to install script" 3
|
||||
fi
|
||||
|
||||
# Security : we shouldn't be able to exit here
|
||||
exit $ERR_IMPOSSIBLE
|
||||
if ! step create_custom_config ; then
|
||||
die "Creating custom configuration file /etc/yunohost/yunohost.conf failed" 4
|
||||
fi
|
||||
|
||||
if ! step confirm_installation ; then
|
||||
die "Installation cancelled at your request" 5
|
||||
fi
|
||||
|
||||
if ! step setup_package_source ; then
|
||||
die "Setting up deb package sources failed" 6
|
||||
fi
|
||||
|
||||
if ! step apt_update ; then
|
||||
die "Error caught during 'apt-get update'" 7
|
||||
fi
|
||||
|
||||
if ! step register_debconf ; then
|
||||
die "Unable to insert new values into debconf database" 8
|
||||
fi
|
||||
|
||||
if ! step workaround_avahi_installation ; then
|
||||
die "Unable to install workaround for avahi installation" 9
|
||||
fi
|
||||
|
||||
if ! step install_yunohost_packages ; then
|
||||
die "Installation of Yunohost packages failed" 10
|
||||
fi
|
||||
|
||||
if ! step restart_services ; then
|
||||
die "Error caught during services restart" 11
|
||||
fi
|
||||
|
||||
if ! step post_install ; then
|
||||
die "Post-installation failed" 12
|
||||
fi
|
||||
|
||||
# Success !
|
||||
success
|
||||
exit 0
|
||||
|
|
Loading…
Add table
Reference in a new issue