ynh-dev/ynh-dev
2016-01-22 22:04:57 +01:00

169 lines
4.8 KiB
Bash
Executable file

#!/bin/bash
usage() {
cat <<EOF
Usage :
On the host
`basename $0` create-env PATH
Create a dev environement into PATH
`basename $0` run DOMAIN [VM VERSION]
Run a docker or virtualbox vm
`basename $0` kill VM
Kill the last docker or all vagrant
Inside the vm
`basename $0` ip
Give the ip of the guest container
`basename $0` upgrade
Upgrade the container
`basename $0` deploy [PAQUET [PAQUET ...]]
Deploy sources to test it
`basename $0` watch [PAQUET [PAQUET ...]]
Deploy sources each time there is change
PAQUET :
moulinette
ssowat
yunohost
yunohost-admin
VM
docker
virtualbox
VERSION
stable8
testing8
unstable8
stable7
testing7
unstable7
EOF
}
check_yunohost_vm() {
if [ ! -d /etc/yunohost ]
then
echo "You need to install YunoHost first. Maybe you are not in a vm ?"
exit 100;
fi
}
paquets=${@:2}
if [ "$#" = "1" ]; then
paquets=('moulinette' 'ssowat' 'yunohost' 'yunohost-admin')
fi
BASE_DIR=/yunohost
if [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "help" ]; then
usage
elif [ "$1" = "create-env" ]; then
set -x
#Create a development environment
pwd=`pwd`
if [ ! "$2" ]
then
echo "I need a destination folder to create the dev environement"
exit 1
fi
[ -e "$2" ] || mkdir -p $2
cd $2
mkdir -p apps
mkdir -p backup
git clone -b unstable https://github.com/Kloadut/SSOwat SSOwat
git clone -b unstable https://github.com/YunoHost/yunohost-admin yunohost-admin
git clone -b unstable https://github.com/YunoHost/yunohost yunohost
git clone -b unstable https://github.com/YunoHost/moulinette moulinette
git clone https://github.com/YunoHost/Dockerfile Dockerfile
git clone https://github.com/zamentur/yunohost-vagrant yunohost-vagrant
cp $pwd/$0 ./$0
ln -s yunohost-vagrant/Vagrantfile Vagrantfile
elif [ "$1" = "run" ]; then
#Run a vm and give a prompt
DOMAIN=$2
VM=$3
VERSION=$4
if [ "$VM" = "docker" ]; then
docker exec -t -i $(sudo docker run -h yunohost.$DOMAIN -v $(pwd):/yunohost -d zamentur/yunohost-$VERSION /sbin/init) /bin/bash
elif [ "$VM" = "virtualbox" ] || [ "$VM" = "vagrant" ]; then
vagrant up $VERSION
vagrant ssh $VERSION
else
echo "This kind of VM is not supported"
exit 100;
fi
elif [ "$1" = "kill" ]; then
VM=$2
if [ "$VM" = "docker" ]; then
docker kill $(docker ps -lq)
elif [ "$VM" = "virtualbox" ] || [ "$VM" = "vagrant" ]; then
vagrant destroy
else
echo "This kind of VM is not supported"
exit 100;
fi
elif [ "$1" = "upgrade" ]; then
check_yunohost_vm
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get -y dist-upgrade
sudo apt-get install -y inotify-tools net-tools
elif [ "$1" = "ip" ]; then
check_yunohost_vm
sudo apt-get install -y net-tools
/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'
elif [ "$1" = "deploy" ]; then
check_yunohost_vm
for i in ${!paquets[@]}; do
case ${paquets[i]} in
moulinette)
# Install moulinette
cd $BASE_DIR/moulinette
./setup.py install
cd ..
[-e "./cache/moulinette/actionsmap/yunohost.pkl"] && rm /var/cache/moulinette/actionsmap/yunohost.pkl
echo "moulinette deployed"
;;
ssowat)
# Install ssowat
sed "s@^@cp -Rf $BASE_DIR/SSOwat/@" $BASE_DIR/SSOwat/debian/install | source /dev/stdin
service nginx stop || true
service nginx start || echo 'Fail to restart nginx'
echo "ssowat deployed"
;;
yunohost)
# Install yunohost
cat ./yunohost/debian/install | awk '{print "mkdir -p " $2}' | source /dev/stdin
sed "s@^@cp -Rf $BASE_DIR/yunohost/@" $BASE_DIR/yunohost/debian/install | source /dev/stdin
service yunohost-api restart || echo 'Fail to restart yunohost-api'
echo "yunohost deployed"
;;
yunohost-admin)
# Install yunohost-admin
sed "s@^@cp -Rf $BASE_DIR/yunohost-admin/@" $BASE_DIR/yunohost-admin/debian/install | source /dev/stdin
echo "yunohost-admin deployed"
;;
esac
done
elif [ "$1" = "watch" ]; then
check_yunohost_vm
sudo apt-get install -y inotify-tools
while inotifywait -r -e close_write $BASE_DIR/moulinette/ $BASE_DIR/SSOwat/ $BASE_DIR/yunohost/ $BASE_DIR/yunohost-admin/; do
$BASE_DIR/$0 deploy ${@:2};
done
else
usage
exit 101
fi
exit 0;