euryspacectl 3.08 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
#!/bin/bash
################################
# Project: EurySPACE CCSDS RX/TX
# Design Name: euryspacectl
# Version: 1.0.0
# Description:
# EurySPACE management tool
# Validated on CentOS 7
# TODO: Ubuntu 16 LTS
################################
# Author(s):
# Guillaume REMBERT
################################
# Licence:
# MIT
################################
# Changes list:
# 2017/09/04: initial release
################################

#Conf for sources / builds
#Install environment (dev / prod) + all / only sub-parts

#############
# FUNCTIONS #
#############

function show_help {
  echo "EurySPACE control tool"
  echo "Usage example:"
  echo "euryspacectl -a ACTION [-d DESTINATION] [-e ENVIRONMENT] [-o OPERATING_SYSTEM] [-t TARGET] [-u USER]"
  echo "ACTION: install"
  echo "DESTINATION: destination folder (default: /home/euryspace)"
  echo "ENVIRONMENT: dev|development, prod|production (default value)"
  echo "OPERATING_SYSTEM: centos7 (default value), ubuntu16"
  echo "TARGET: all (default value), space|space_segment, ground|ground_segment, user|user_segment"
  echo "USER: user used to start (default: astronaut)"
}

START_TIME=$(date +%s)

####################
# SCRIPT VARIABLES #
####################
EURYSPACE_PRODUCTION=true
EURYSPACE_OPERATING_SYSTEM="centos7"
EURYSPACE_USER="astronaut"

#########################
# SCRIPT INITIALISATION #
#########################
#Check script is run as root
if [[ $EUID -ne 0 ]]; then
  echo "This script must be run as root" 1>&2
  exit 1
fi
#Get configuration variables and functions
SCRIPT_COMMAND=$(readlink -f "$0")
SCRIPT_PATH=$(dirname "$SCRIPT_COMMAND")
#Should not be changed except if you changed sw folder layout
SCRIPT_CONF_PATH=$SCRIPT_PATH/cfg/sw/euryspace.conf
#Get input parameters
while getopts :a:e:ht: ARGUMENT
do
  case "${ARGUMENT}" in
    a) SCRIPT_ACTION=${OPTARG}
      case "${SCRIPT_ACTION}" in
        install)
        ;;
        *)
          echo "Unknown action: ${SCRIPT_ACTION}" 1>&2
          show_help
          exit 1
        ;;
      esac
    ;;
    d) EURYSPACE_DESTINATION=${OPTARG}
    ;;
    e) ENVIRONMENT=${OPTARG}
      case "${ENVIRONMENT}" in
        dev|development)
          EURYSPACE_PRODUCTION=false
        ;;
        prod|production)
          echo "Production environment is not yet managed" 1>&2
          exit 1
        ;;
        *)
          echo "Unknown enviroment: ${ENVIRONMENT}" 1>&2
          show_help
          exit 1
      esac
    ;;
    h)
      show_help
      exit 0
    ;;
    o) EURYSPACE_OPERATING_SYSTEM=${OPTARG}
      case "${EURYSPACE_OPERATING_SYSTEM}" in
        ubuntu16|centos7)
        ;;
        *)
          echo "Unmanaged operating system: ${EURYSPACE_OPERATING_SYSTEM}" 1>&2
          show_help
          exit 1
      esac
    ;;
    t) TARGET=${OPTARG}
    ;;
    u) EURYSPACE_USER=${OPTARG}
    ;;
    ?)
      echo "Unknown argument: ${OPTARG}" 1>&2
      show_help
      exit 1
    ;;
  esac
done

case "${SCRIPT_ACTION}" in
  install)
    $SCRIPT_PATH/sw/src/tools/euryspace_install.sh ${EURYSPACE_OPERATING_SYSTEM} ${EURYSPACE_PRODUCTION} ${EURYSPACE_USER} ${EURYSPACE_DESTINATION}
  ;;
esac