echo -e " Inits openmano database; deletes previous one and loads from ${DBNAME}_structure.sql"
echo -e " OPTIONS"
echo -e " -u USER database user. '$DBUSER' by default. Prompts if DB access fails"
- echo -e " -p PASS database password. 'No password' by default. Prompts if DB access fails"
+ echo -e " -p PASS database password. 'No password' or 'manopw' by default. Prompts if DB access fails"
echo -e " -P PORT database port. '$DBPORT' by default"
echo -e " -h HOST database host. '$DBHOST' by default"
echo -e " -d NAME database name. '$DBNAME' by default. Prompts if DB access fails"
TEMPFILE="$(mktemp -q --tmpdir "initmanodb.XXXXXX")"
trap 'rm -f "$TEMPFILE"' EXIT
chmod 0600 "$TEMPFILE"
-cat >"$TEMPFILE" <<EOF
-[client]
-user="${DBUSER}"
-password="${DBPASS}"
-EOF
DEF_EXTRA_FILE_PARAM="--defaults-extra-file=$TEMPFILE"
+if [ -z "${DBPASS}" ]
+then
+ password_ok=""
+ echo -e "[client]\nuser='${DBUSER}'\npassword='manopw'" > "$TEMPFILE"
+ mysql --defaults-extra-file="$TEMPFILE" $DBHOST_ $DBPORT_ $DBNAME -e "quit" >/dev/null 2>&1 && DBPASS="manopw"
+ echo -e "[client]\nuser='${DBUSER}'\npassword=''" > "$TEMPFILE"
+ mysql --defaults-extra-file="$TEMPFILE" $DBHOST_ $DBPORT_ $DBNAME -e "quit" >/dev/null 2>&1 && DBPASS=""
+fi
+echo -e "[client]\nuser='${DBUSER}'\npassword='${DBPASS}'" > "$TEMPFILE"
while ! mysql $DEF_EXTRA_FILE_PARAM $DBHOST_ $DBPORT_ -e "quit" >/dev/null 2>&1
do
read -e -p "mysql user($DBUSER): " KK
[ -n "$KK" ] && DBUSER="$KK"
read -e -s -p "mysql password: " DBPASS
- cat >"$TEMPFILE" <<EOF
-[client]
-user="${DBUSER}"
-password="${DBPASS}"
-EOF
+ echo -e "[client]\nuser='${DBUSER}'\npassword='${DBPASS}'" > "$TEMPFILE"
logintry="yes"
echo
done
+[ -z "${DBPASS}" ] && DBPASS_=""
+[ -n "${DBPASS}" ] && DBPASS_="-p${DBPASS}"
if [ -n "${CREATEDB}" ]; then
echo " deleting previous database ${DBNAME}"
function usage(){
echo -e "usage: sudo $0 [OPTIONS]"
- echo -e "Configures openmano to run as a service"
+ echo -e "Configures openmano to run as a service at /opt"
echo -e " OPTIONS"
echo -e " -u USER_OWNER user owner of the service, 'root' by default"
echo -e " -f PATH path where openmano source is located. If missing it is downloaded from git"
- #echo -e " -q: install in an unattended mode"
+ echo -e " -d --delete: if -f is provided, delete this path after copying to /opt"
echo -e " -h: show this help"
echo -e " --uninstall: remove created service and files"
}
USER_OWNER="root"
QUIET_MODE=""
FILE=""
-while getopts ":u:f:hq-:" o; do
+DELETE=""
+while getopts ":u:f:hdq-:" o; do
case "${o}" in
u)
export USER_OWNER="$OPTARG"
h)
usage && exit 0
;;
+ d)
+ DELETE=y
+ ;;
-)
[ "${OPTARG}" == "help" ] && usage && exit 0
[ "${OPTARG}" == "uninstall" ] && uninstall && exit 0
- echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2
+ [ "${OPTARG}" == "delete" ] && DELETE=y && continue
+ echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2
exit 1
;;
\?)
then
FILE=__temp__${RANDOM}
git clone $GIT_URL $FILE || ! echo "Cannot get openmano source code from $GIT_URL" >&2 || exit 1
+ DELETE=y
else
[[ -d "$FILE" ]] || ! echo $BAD_PATH_ERROR >&2 || exit 1
fi
ln -s -v /opt/openmano/scripts/service-openmano.sh /usr/sbin/service-openmano
ln -s -v /opt/openmano/scripts/openmano-report.sh /usr/bin/openmano-report
-chown -R $USER_OWNER /opt/openmano
+chown -R $SUDO_USER /opt/openmano
mkdir -p /etc/systemd/system/
cat > /etc/systemd/system/openmano.service << EOF
WantedBy=multi-user.target
EOF
-rm -rf ${FILE}
+[[ -n $DELETE ]] && rm -rf ${FILE}
service openmano start
systemctl enable openmano.service
[[ "$_DISTRO" == "Ubuntu" ]] && [[ ${_RELEASE%%.*} == 16 ]] && [[ -z $DEVELOP ]] && INSTALL_AS_A_SERVICE="y"
#Next operations require knowing OPENMANO_BASEFOLDER
if [[ -z "$NOCLONE" ]]; then
- OPENMANO_BASEFOLDER="${PWD}/openmano"
- [[ -n "$FORCE" ]] && rm -rf $OPENMANO_BASEFOLDER #make idenpotent
+ if [[ -n "$INSTALL_AS_A_SERVICE" ]] ; then
+ OPENMANO_BASEFOLDER=__openmano__${RANDOM}
+ else
+ OPENMANO_BASEFOLDER="${PWD}/openmano"
+ fi
+ [[ -n "$FORCE" ]] && rm -rf $OPENMANO_BASEFOLDER #make idempotent
else
HERE=$(realpath $(dirname $0))
OPENMANO_BASEFOLDER=$(dirname $HERE)
su $SUDO_USER -c 'rm -f ${HOME}/bin/openmano'
su $SUDO_USER -c 'rm -f ${HOME}/bin/openmano-report'
su $SUDO_USER -c 'rm -f ${HOME}/bin/service-openmano'
- su $SUDO_USER -c 'ln -s '${OPENMANO_BASEFOLDER}'/openmano ${HOME}/bin/openmano'
- su $SUDO_USER -c 'ln -s '${OPENMANO_BASEFOLDER}'/scripts/openmano-report.sh ${HOME}/bin/openmano-report'
- su $SUDO_USER -c 'ln -s '${OPENMANO_BASEFOLDER}'/scripts/service-openmano.sh ${HOME}/bin/service-openmano'
+ su $SUDO_USER -c "ln -s '${OPENMANO_BASEFOLDER}/openmano' "'${HOME}/bin/openmano'
+ su $SUDO_USER -c "ln -s '${OPENMANO_BASEFOLDER}/scripts/openmano-report.sh' "'${HOME}/bin/openmano-report'
+ su $SUDO_USER -c "ln -s '${OPENMANO_BASEFOLDER}/scripts/service-openmano.sh' "'${HOME}/bin/service-openmano'
#insert /home/<user>/bin in the PATH
#skiped because normally this is done authomatically when ~/bin exist
##### CONFIGURE OPENMANO SERVICE #####
#################################################################'
- ${OPENMANO_BASEFOLDER}/scripts/install-openmano-service.sh -f ${OPENMANO_BASEFOLDER} #-u $SUDO_USER
+ ${OPENMANO_BASEFOLDER}/scripts/install-openmano-service.sh -f ${OPENMANO_BASEFOLDER} `[[ -z "$NOCLONE" ]] && echo "-d"`
# rm -rf ${OPENMANO_BASEFOLDER}
# alias service-openmano="service openmano"
# echo 'alias service-openmano="service openmano"' >> ${HOME}/.bashrc
echo -e " --screen forces to run openmano (and openvim) service in a screen"
echo -e " --insert-bashrc insert the created tenant,datacenter variables at"
echo -e " ~/.bashrc to be available by openmano CLI"
+ echo -e " --install-openvim install openvim in test mode"
echo -e " --init-openvim if openvim runs locally, an init is called to clean openvim"
echo -e " database and add fake hosts"
}
#process options
-source ${DIRscript}/get-options.sh "force:f help:h insert-bashrc init-openvim screen" $* || $_exit 1
+source ${DIRscript}/get-options.sh "force:f help:h insert-bashrc init-openvim install-openvim screen" $* || $_exit 1
#help
[ -n "$option_help" ] && usage && $_exit 0
#by default action should be reset and create
[[ -z $action_list ]] && action_list="reset create delete"
+
+if [[ -n "$option_install_openvim" ]]
+then
+ pushd ${DIRmano}/..
+ echo "installing openvim at $PWD/openvim ... "
+ wget -O install-openvim.sh "https://osm.etsi.org/gitweb/?p=osm/openvim.git;a=blob_plain;f=scripts/install-openvim.sh"
+ chmod +x install-openvim.sh
+ sudo ./install-openvim.sh --no-install-packages --force --quiet --develop
+ alias initopenvim="${PWD}/openvim/scripts/initopenvim.sh"
+ alias openvim="${PWD}/openvim/scripts/openvim"
+ option_init_openvim="-"
+ popd
+fi
[[ -z "$option_init_openvim" ]] || initopenvim${force_param}${insert_bashrc_param}${screen_vim_param} || echo "WARNING openvim cannot be initialized. The rest of test can fail!"
#check openvim client variables are set