-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_git
executable file
·60 lines (45 loc) · 1.37 KB
/
setup_git
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
# Ensure all commands below will be successful or fail if not
set -e
# Enter password if called by ssh-add
[ -n "$SSH_ASKPASS" ] && [ -n "$DISPLAY" ] && {
[ ! -f ".ssh-add" ]
touch .ssh-add
echo "$KEY_PASS"
exit 0
}
echo && echo "Initializing Git environment..."
GIT_NAME="Lapislazuli"
GIT_EMAIL="[email protected]"
KEY_NAME=lapislazuli.pem
# We don't need to set up anything if we don't have the passphrase
[[ -z "$KEY_PASS" || ( -n "$TRAVIS_SECURE_ENV_VARS" && "$TRAVIS_SECURE_ENV_VARS" = "false" ) ]] && {
echo "Passphrase is not available, unable to set up Git environment."
exit 1
}
KEY_PATH=~/.ssh/$KEY_NAME
# This is where I am.
deploy_scripts=$(dirname $0)
mkdir -pv $(dirname $KEY_PATH)
cp -v "$deploy_scripts/$KEY_NAME" $KEY_PATH
# Change the permissions so it is accepted as SSH key
chmod -v 600 $KEY_PATH
# Setup detached ASKPASS for ssh
export SSH_ASKPASS=$0
export DISPLAY=dummydisplay:0
cleanup() {
unset SSH_ASKPASS DISPLAY KEY_PASS
rm .ssh-add
}
true | setsid ssh-add "$KEY_PATH" || {
cleanup
echo "Failed to add private Git key. Maybe the passphrase is wrong?"
exit 1
}
cleanup
echo "Successfully installed Git SSH key!"
echo "Setting up Git settings..."
git config --global user.name "$GIT_NAME"
git config --global user.email "$GIT_EMAIL"
git config --global push.default simple
echo "Done! Successfully set up Git environment. :)" && echo