You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

132 lines
3.7 KiB

#!/bin/bash
## Installing base docker-host
wget http://docker.0k.io/get/ -qO - | bash
## shlib is now available
. /etc/shlib || {
echo "shlib is not available. Bailing out." >&2
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
clone_or_update pandachi-manage || exit 1
install_bin /opt/apps/pandachi-manage/bin
clone_or_update pandachi-deploy || exit 1
#[ -e /etc/compose.conf ] || ln -sfv /opt/apps/pandachi-deploy/etc/compose.conf /etc/compose.conf
## XXXvlab: should get rid of this file in some future
cd /opt/apps/pandachi-deploy
if ! grep "^DEFAULT_COMPOSE_FILE=$PWD/compose.yml$" /etc/compose/local.conf >/dev/null 2>&1; then
echo "Adding CWD=$PWD to docker-compose."
cat <<EOF >> /etc/compose/local.conf
DEFAULT_COMPOSE_FILE=$PWD/compose.yml
EOF
fi
type -t docker-clean || ln -sfv /opt/apps/0k-docker/src/bin/docker-clean /usr/local/bin
echo "Login into our server."
docker login -u deploy -p deployinvm git.panda-chi.io:5002
cd /opt/apps/pandachi-deploy
cat <<EOF > /root/.pgm.rc
prefix_pg_local_command=" " ## otherwise, will default to sudo -u postgres
pgpass="/srv/datastore/data/postgres/var/lib/postgresql/data/pgpass"
[ -f "\$pgpass" ] || {
echo "No '\$pgpass' found. Postgres database doesn't seem to be setup." >&2
exit 1
}
cp "\$pgpass" /root/.pgpass
PGUSER=\${PGUSER:-postgres}
if [ -z "\$PGHOST" ]; then
PGHOST=\$(docker-ip | grep postgres | xargs echo | cut -f 3 -d " ") || {
echo "No local running postgres docker found." >&2
exit 1
}
fi
export PGHOST PGUSER
EOF
if ! [ -s /etc/ssh/vm_git_myceliandre_access_id_rsa ]; then
curl https://docker.0k.io/get/vm_git_myceliandre_access_id_rsa > /etc/ssh/vm_git_myceliandre_access_id_rsa || {
echo "Fatal: Could not retrieve http://docker.0k.io/get/vm_git_myceliandre_access_id_rsa ..." >&2
rm -f /etc/ssh/vm_git_myceliandre_access_id_rsa
exit 1
}
## Not so usefull as it is public !
chmod 0600 /etc/ssh/vm_git_myceliandre_access_id_rsa
fi
mkdir -p /root/.ssh
cat <<EOF >> /root/.ssh/config
Host git.myceliandre.fr
User git
IdentityFile /etc/ssh/vm_git_myceliandre_access_id_rsa
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
Port 5022
EOF
##
## We could need some docker-compose for some quick hacks
##
apt-get install -y build-essential </dev/null # seems to require a C compiler
pip install pip==19.3.1 cffi==1.12.3 subprocess32==3.5.4 texttable==1.6.2 \
git+https://github.com/0k/compose@run_ignore_orphans
hash -d pip ## Bug after updating pip
if [ "$DOMAIN" ]; then
sed -ri "s/^(\s+domain:\s+).*$/\1$DOMAIN/g" compose.yml
fi
if [ "$MAIN_PASSWORD" ]; then
sed -ri "s/^(\s+admin-password:\s+).*$/\1$MAIN_PASSWORD/g" compose.yml
fi
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