-#!/bin/bash
-
-usage() {
-cat <<EOF
- $0 [options]
- --help,-h This help
- --instance-id id Id of the instance
- --reinstall-first Start with reinstalling the vps
- --host-user user Use another user (default: arch)
- --no-reboot Don't reboot
- --no-reboot-start Don't reboot to rescue at the beginning
- --no-reboot-end Don't reboot to normal at the end
- --git-branch Use another puppet branch (default: master)
- --environment Environment to use for the installl (default: production)
-EOF
-}
-
-set -e
-
-host_user=arch
-git_branch=master
-environment=production
-
-while [ -n "$1" ]; do
- case "$1" in
- --instance-id)
- instance_id="$2"
- shift
- ;;
- --reinstall-first)
- reinstall_first=1
- ;;
- --host-user)
- host_user="$2"
- shift
- ;;
- --no-reboot)
- no_reboot=1
- ;;
- --no-reboot-start)
- no_reboot_start=1
- ;;
- --no-reboot-end)
- no_reboot_end=1
- ;;
- --git-branch)
- git_branch="$2"
- shift
- ;;
- --environment)
- environment="$2"
- shift
- ;;
- --help|-h)
- usage
- exit 0
- ;;
- esac
-
- shift
-done
-
-DIRECTORY=$(cd `dirname $0` && pwd)
-PYTHON_DIRECTORY="$DIRECTORY/../python"
-SCRIPTS="$DIRECTORY/../scripts"
-
-if [ -z "$instance_id" ]; then
- read -p "Id de l'instance : " instance_id
-fi
-
-if [ -n "$reinstall_first" ]; then
- echo "Réinstallation du système"
- python $PYTHON_DIRECTORY/reinstall_cloud_instance.py --use-current "$instance_id"
-
- read -p "Appuyer sur une touche quand le serveur est prêt" ready
-fi
-
-if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
- echo "Patienter le temps du reboot"
- python $PYTHON_DIRECTORY/reboot_cloud_instance.py --rescue "$instance_id"
-
- read -p "Appuyer sur une touche quand l'instance a redémarré" ready
-fi
-
-ARCH_DIR=`mktemp -d`
-ARCH_HOST_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_script.sh"
-ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
-ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_puppet_configuration_script.sh"
-ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
-ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
-
-trap "rm -rf $ARCH_DIR" EXIT
-
-#### Base installation stage
-python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id > $ARCH_PUPPET_INITIAL_CONFIGURATION
-host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id | jq -r '.ips.v4.ipAddress')
-
-dest="$host_user@$host_address"
-files="$ARCH_HOST_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT"
-
-$SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files
-
-### Role specific stage
-read -p "Press key when LDAP is configured" i
-
-files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT"
-
-$SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files
-
-### Installation finished
-if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
- echo "Rebooting"
- python $PYTHON_DIRECTORY/reboot_cloud_instance.py --local "$instance_id"
-fi