-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasic-git.sh
73 lines (63 loc) · 2.23 KB
/
basic-git.sh
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
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
clear
#take path of public folder and create it
echo "Please enter ABSOLUTE PATH of web server public folder for this project, that will be your publicly visible web folder (for Apache /var/www/html/...)"
read webFolderPath
while true; do
read -p "You entered: $webFolderPath is that correct path? y/n?" yn
case $yn in
[Yy]* ) mkdir -p $webFolderPath; break;;
[Nn]* ) echo "Script stopped"; exit;;
* ) echo "Please answer yes or no.";;
esac
done
#cd into public folder and initialize git there
cd $webFolderPath; git init;
#take path of bare git repository and create it
echo "Please enter ABSOLUTE PATH of bare git repo, that will be you main entry point for pushing/pulling to remote server, one that ends with .git: "
read gitBareRepo
while true; do
read -p "You entered: $gitBareRepo is that correct path? y/n?" yn
case $yn in
[Yy]* ) mkdir -p $gitBareRepo; break;;
[Nn]* ) echo "Script stopped"; exit;;
* ) echo "Please answer yes or no.";;
esac
done
#cd into git bare repository and initialize bare repository there
cd $gitBareRepo; git init --bare;
#define bare repository as hub of public folder
cat <<EOT > $webFolderPath"/.git/config"
[remote "hub"]
url = $gitBareRepo
fetch = +refs/heads/*:refs/remotes/hub/*
EOT
#create post-update hook in git bare repository, for syncing files with public folder
cat <<EOT > $gitBareRepo"/hooks/post-update"
#!/bin/sh
echo
echo "**** Pulling changes into Live [Hub's post-update hook]"
echo
cd $webFolderPath || exit
unset GIT_DIR
git pull hub master
exec git-update-server-info
EOT
#create post-commit to sync back with bare repository,
#if you decide to change something directly from public folder
cat <<EOT > $webFolderPath"/.git/hooks/post-commit"
#!/bin/sh
echo
echo "**** pushing changes to Hub [Live's post-commit hook]"
echo
git push hub
EOT
#take username that will use this repository
echo -e "Please enter server username of user that will be using this repository: \c "
read username
#add execute permission to 2 hooks
sudo chmod +x $webFolderPath"/.git/hooks/post-commit";
sudo chmod +x $gitBareRepo"/hooks/post-update";
#customize ownership over files
sudo chown -R $username $webFolderPath;
sudo chown -R $username $gitBareRepo;