Skip to content

Instantly share code, notes, and snippets.

@TommyLau
Created March 3, 2015 04:16
Show Gist options
  • Save TommyLau/9710c7275d36d3ba1d43 to your computer and use it in GitHub Desktop.
Save TommyLau/9710c7275d36d3ba1d43 to your computer and use it in GitHub Desktop.
Stash post receive hooks
#!/bin/bash
# Make a temp file
keyfile=`mktemp`
# Get repository to push
repository="$1"
# Create the private key
while shift; do
echo "$1" >> $keyfile
done
chmod 0600 $keyfile
# Generate a temp ssh.sh
ssh=`mktemp`
cat <<-EOF>$ssh
#!/bin/bash
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $keyfile "\$@"
EOF
chmod +x $ssh
# Push to remote to publish
GIT_SSH=$ssh git push --mirror $repository
#ssh-agent bash -c "ssh-add $keyfile; git push --mirror $repository >> output.txt"
# Remove temp files
rm -f $keyfile
rm -f $ssh
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment