Last active
December 26, 2015 19:29
-
-
Save plietar/7201430 to your computer and use it in GitHub Desktop.
Dokku git plugin migration script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
DOKKU_ROOT=/home/dokku | |
GIT_HOME=/home/git | |
# Old repo files of when PPAs were used. Remove them | |
rm -f /etc/apt/sources.list.d/dotcloud-lxc-docker-raring.list* | |
# Stop and get rid of the nginx-reload daemon if it the user is upgrading from and old version (pre PR #262) | |
stop nginx-reloader || true | |
rm -f /etc/init/nginx-reloader.conf | |
# .sshcommand is the only file we need to save | |
cp $DOKKU_ROOT/.sshcommand $GIT_HOME | |
rm -Rf $DOKKU_ROOT | |
mv $GIT_HOME $DOKKU_ROOT | |
deluser git | |
chown dokku:dokku -R $DOKKU_ROOT | |
rm -f $DOKKU_ROOT/receiver | |
# Change gitreceive into sshcommand | |
sed -i 's#/usr/local/bin/gitreceive run \([^ ]\+\) \(\([0-9a-f][0-9a-f]:\?\)*\)#FINGERPRINT=\2 NAME=\1 `cat /home/dokku/.sshcommand` $SSH_ORIGINAL_COMMAND#' $DOKKU_ROOT/.ssh/authorized_keys | |
# Allow pty | |
sed -i 's#no-pty,##' $DOKKU_ROOT/.ssh/authorized_keys | |
# fix prereceive hooks | |
for APP_PATH in $(ls -d $DOKKU_ROOT/*/); do | |
APP=$(basename $APP_PATH) | |
PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive" | |
cat > $PRERECEIVE_HOOK <<EOF | |
#!/usr/bin/env bash | |
set -e; set -o pipefail; | |
cat | DOKKU_ROOT="$DOKKU_ROOT" dokku git-hook $APP | |
EOF | |
chmod +x $PRERECEIVE_HOOK | |
done | |
touch /etc/sudoers.tmp | |
cp /etc/sudoers /tmp/sudoers.new | |
sed -i '/%git ALL=(ALL)NOPASSWD:\/etc\/init.d\/nginx reload # dokku-nginx-reload/d' /tmp/sudoers.new | |
EDITOR="cp /tmp/sudoers.new" visudo | |
rm /tmp/sudoers.new | |
rm /usr/local/bin/gitreceive | |
cat <<EOF | |
Migration succeeded ! | |
Run "make install" and "dokku deploy:all" to complete | |
You will need to change your git remotes. | |
EOF | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment