Skip to content

Instantly share code, notes, and snippets.

@ragusa87
Last active April 4, 2019 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ragusa87/b2b5d07c5a934718bbc6582824605bce to your computer and use it in GitHub Desktop.
Save ragusa87/b2b5d07c5a934718bbc6582824605bce to your computer and use it in GitHub Desktop.
Liip clone moodle repo (private)
#!/bin/bash
set -xe
MOODLE_REPO=git@gitlab.liip.ch:elearning/moodle.git
MOODLE_CACHE=~/gitcaches/moodle.reference
MOODLE_ALTERNATE_REPO=git@gitlab.liip.ch:elearning/moodle-testmigration.git
MOODLE_ALTERNATE_REPO_NAME=test
if [[ $# -eq 0 ]]; then
echo "Entrez le nom de la branche client: [mdl31-tcs]: "
read branch
else
branch=$1
fi
if [ "$branch" = "" ] || [ "$branch" = "--" ]; then
git ls-remote -h $MOODLE_REPO
exit
fi
echo "Cloning branch $branch..."
# create the mirror if it doesn't exist
if [ ! -d $MOODLE_CACHE ]; then
git clone --mirror --recursive $MOODLE_REPO $MOODLE_CACHE
fi
# Clone with the mirror info
git clone -b $branch --reference $MOODLE_CACHE $MOODLE_REPO $branch
# Add the generic config for drifter
cd $branch
ln -s virtualization/config.php
# Handle submodules update
git submodule update --init --recursive || true
# Add upstream
git remote add upstream https://github.com/moodle/moodle || true
# Add alternate repo
git remote add $MOODLE_ALTERNATE_REPO_NAME $MOODLE_ALTERNATE_REPO || true
git fetch --all
#!/bin/bash
set -xe
MOODLE_REPO=git@gitlab.liip.ch:elearning/moodle-testmigration.git
MOODLE_REPO_NAME=test
MOODLE_CACHE=~/gitcaches/moodle-testmigration.reference
MOODLE_ALTERNATE_REPO=git@gitlab.liip.ch:elearning/moodle.git
MOODLE_ALTERNATE_REPO_NAME=liip
if [[ $# -eq 0 ]]; then
echo "Entrez le nom de la branche client: [mdl31-tcs]: "
read branch
else
branch=$1
fi
if [ "$branch" = "" ] || [ "$branch" = "--" ]; then
git ls-remote -h $MOODLE_REPO
exit
fi
echo "Cloning branch $branch..."
# TODO create the mirror if it doesnt exists
if [ ! -d $MOODLE_CACHE ]; then
git clone --mirror --recursive $MOODLE_REPO $MOODLE_CACHE
fi
# TODO Clone with the mirror info
# git clone --mirror $MOODLE_REPO $MOODLE_CACHE
git clone -b $branch --reference $MOODLE_CACHE $MOODLE_REPO $branch
cd $branch
ln -s virtualization/config.php
git submodule update --init --recursive || true
# Set name
if [[ $MOODLE_REPO_NAME != "origin" ]]; then
git remote rename origin $MOODLE_REPO_NAME
fi
# Add upstream
git remote add upstream https://github.com/moodle/moodle || true
# Add alternate repo
git remote add $MOODLE_ALTERNATE_REPO_NAME $MOODLE_ALTERNATE_REPO || true
git fetch --all
#!/bin/bash
#
# Parse the projectinfo and try to get the daily_dump from the remote server
# Note that this is not 100% working but helps most of the time
#
set -x
if [ ! -f projectinfo.yml ]; then
echo "No projectinfo found"
exit 1
fi
if [ "$#" -eq "0" ]; then
instance_env=staging
else
echo -n "Using custom instance env: "
echo $1 echo "Hello world"
instance_env=$1
fi
# https://gist.github.com/pkuczynski/8665367
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}
}'
}
eval $(parse_yaml projectinfo.yml "config_")
hostvar="config_${instance_env}_host"
codenamevar="config_${instance_env}_codename"
config_host=${!hostvar}
codename=${!codenamevar}
if [ -z $codename ]; then
codename=$config_codename
fi
echo "Using $config_host"
SSH_HOST=$(echo $config_host | awk '{sub(/:[0-9]+/,"",$1);print}' | awk -F\' '{print $1}')
SSH_PORT=$(echo $config_host | grep -oE '\:([0-9]+)' | awk -F: '{ print $2 }' )
if [ -z $SSH_PORT ]; then
SSH_PORT=22
fi
scp -P $SSH_PORT $SSH_HOST:~/websites/$codename/shared/daily_dbdump.pgdump $config_codename-${instance_env}-$(date +%Y-%m-%d).pgdump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment