From d8a930123aef78738662fd61b56977212e2ce082 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Tue, 15 Oct 2019 13:15:36 +0200 Subject: [PATCH] chg: dev: [pandachi-install] streamline installation and update in functions --- bin/pandachi-install | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/bin/pandachi-install b/bin/pandachi-install index 9f9a430..aedfeb1 100755 --- a/bin/pandachi-install +++ b/bin/pandachi-install @@ -9,19 +9,40 @@ wget http://docker.0k.io/get/ -qO - | bash exit 1 } + +clone_or_update() { + local pkg="$1" branch=${2:-master} \ + DEPLOY_PATH="/opt/apps" \ + GIT_BASE="git.0k.io:/var/git/0k" \ + current_branch + if [ -d "$DEPLOY_PATH/$pkg" ]; then + cd "$DEPLOY_PATH/$pkg" + current_branch=$(git rev-parse --abbrev-ref HEAD) + if [ "$current_branch" != "$branch" ]; then + echo "Fatal: $DEPLOY_PATH/$pkg git repos has unexpected branch checkouted." + echo " To avoid changing thing, we prefer to bailout." + return 1 + fi + git pull -r || return 1 + else + mkdir -p "$DEPLOY_PATH" && cd "$DEPLOY_PATH" + git clone "$GIT_BASE/${pkg}" -b "$branch" --depth=1 + fi +} + +install_bin() { + local path="$1" DEST_PATH=/usr/local/bin + ln -sfnv "$path"/* "$DEST_PATH" || return 1 + find -L "$DEST_PATH" -maxdepth 1 -type l -ilname "$path"/\* -exec rm -v {} \; || return 1 +} + set -e -if ! [ -d "/opt/apps/pandachi-deploy" ]; then - mkdir -p /opt/apps && cd /opt/apps - git clone git.0k.io:/var/git/0k/pandachi-deploy.git -fi +clone_or_update pandachi-manage || exit 1 +install_bin /opt/apps/pandachi-manage/bin -if ! [ -d "/opt/apps/pandachi-manage" ]; then - mkdir -p /opt/apps && cd /opt/apps - git clone git.0k.io:/var/git/0k/pandachi-manage.git -fi +clone_or_update pandachi-deploy || exit 1 -ln -sfn /opt/apps/pandachi-manage/bin/* /usr/local/bin/ #[ -e /etc/compose.conf ] || ln -sfv /opt/apps/pandachi-deploy/etc/compose.conf /etc/compose.conf @@ -97,11 +118,10 @@ if [ "$MAIN_PASSWORD" ]; then sed -ri "s/^(\s+admin-password:\s+).*$/\1$MAIN_PASSWORD/g" compose.yml fi -pip install ovh -ln -sf /opt/apps/pandachi-deploy/bin/* /usr/local/bin/ +pip install ovh #compose --debug up odoo apache ## Marker to probe if this script finished it's job -echo "done" > /var/run/pandachi-installer.0k.io.state \ No newline at end of file +echo "done" > /var/run/pandachi-installer.0k.io.state