From: Sébastien Han Date: Wed, 20 Jul 2016 14:47:53 +0000 (+0200) Subject: aio: more flexible script X-Git-Tag: v1.0.6~50^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F894%2Fhead;p=ceph-ansible.git aio: more flexible script we can now chose the install source Signed-off-by: Sébastien Han --- diff --git a/ceph-aio-no-vagrant.sh b/ceph-aio-no-vagrant.sh index 03e189c72..0a68fa3c0 100755 --- a/ceph-aio-no-vagrant.sh +++ b/ceph-aio-no-vagrant.sh @@ -5,41 +5,113 @@ # to work properly. set -e -if [[ -z $1 ]]; then - CEPH_BRANCH_DEFAULT=master -else - CEPH_BRANCH_DEFAULT=$1 -fi -CEPH_BRANCH=${CEPH_BRANCH:-$CEPH_BRANCH_DEFAULT} + +# VARIABLES + +SOURCE=stable +IP=$(ip -4 -o a | awk '/eth|ens|eno|enp|em|p.p./ { sub ("/..", "", $4); print $4 }' | head -1) SUBNET=$(ip r | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/[0-9]\{1,2\}' | head -1) -MON_IP=$(ip -4 -o a | awk '/eth/ { sub ("/..", "", $4); print $4 }') - -if [[ $EUID -ne 0 ]]; then - echo "You are NOT running this script as root." - echo "You should." - echo "Really." - echo "PLEASE RUN IT WITH SUDO ONLY :)" - exit 1 + + +# FUNCTIONS + +show_help() { + PROG=$(basename $0) + echo "" + echo "Usage of ${PROG}:" + cat << EOF + +None of the following options are mandatory! + +-h : HELP, show this help & exit +-s stable : INSTALL SOURCE, valid values are 'stable' or 'dev' (DEFAULT: stable) +-b master : DEV BRANCH, only valid when '-s dev' (DEFAULT: master) +-i 192.168.0.1 : IP, if not set the first IP of the stack will be used +-n 192.168.0.0/24 : Subnet, if not set the first subnet of the stack will be used + +Examples: +${PROG} -s stable # installs latest stable version and detects IP/SUBNET +${PROG} -s stable -i 192.168.0.1 -n 192.168.0.0/24 # installs latest stable version and use the provided IP/SUBNET +${PROG} -s dev -b master # installs master branch version and detects IP/SUBNET +${PROG} -s dev -b master -i 192.168.0.1 -n 192.168.0.0/24 # installs master branch version and use the provided IP/SUBNET +EOF +} + +parse_cmdline() { +while getopts "hs:b:i:n:" opt; do + case $opt in + h) + show_help + exit 0 + ;; + s) + SOURCE=${OPTARG} + ;; + b) + BRANCH=${OPTARG} + ;; + i) + IP=${OPTARG} + ;; + n) + SUBNET=${OPTARG} + ;; + \?) + exit 1 + ;; + : ) + exit 1 + ;; + esac +done + +if [ $# -eq 0 ]; then + show_help + exit 0 +fi + +if [[ ${SOURCE} == 'stable' && ! -z ${BRANCH} ]]; then + echo "You can not use a stable install source and a specific branch!" + echo "A branch can be specified when a 'dev' source is desired". + echo "Run the script with -h for examples." + exit 1 fi -sudo bash install-ansible.sh +} -ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa -cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys -cp group_vars/all.sample group_vars/all -cp group_vars/osds.sample group_vars/osds +function install_ansible { + sudo bash install-ansible.sh +} -sed -i "s/#osd_auto_discovery: false/osd_auto_discovery: true/" group_vars/osds -sed -i "s/#journal_collocation: false/journal_collocation: true/" group_vars/osds -sed -i "s/#ceph_dev: false/ceph_dev: true/" group_vars/all -sed -i "s/#pool_default_size: 3/pool_default_size: 2/" group_vars/all -sed -i "s/#monitor_address: 0.0.0.0/monitor_address: ${MON_IP}/" group_vars/all -sed -i "s/#journal_size: 0/journal_size: 100/" group_vars/all -sed -i "s|#public_network: 0.0.0.0\/0|public_network: ${SUBNET}|" group_vars/all -sed -i "s/#common_single_host_mode: true/common_single_host_mode: true/" group_vars/all -sed -i "s|#ceph_dev_branch: master|ceph_dev_branch: ${CEPH_BRANCH}|" group_vars/all +function ssh_setup { + echo -e 'y\n'|ssh-keygen -q -t rsa -N "" -f ~/.ssh/id_rsa + cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys +} -cat > /etc/ansible/hosts < /etc/ansible/hosts < /dev/null ; then echo "Ansible is already installed." echo "Doing nothing." echo "Exiting now." - exit 1 + exit 0 fi if [[ $EUID -ne 0 ]]; then