-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
executable file
·107 lines (93 loc) · 2.49 KB
/
setup
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#! /bin/bash
set -Eeuo pipefail;
password="";
default_branch="master";
# Usage instructions
print_usage() {
echo "";
echo "Usage:";
echo "";
echo "./setup --pwd <value> [--help] [--default-branch <branch_name>]";
echo "";
echo "--pwd <value>";
echo " Password for the Git server account. Used for SSH as well.";
echo " Value: A string. An empty string is not allowed.";
echo " Requirement: Always";
echo "";
echo "--default-branch <branch_name>";
echo " Optionally specify the default branch that Git should use for the initial branch.";
echo " Value: A string. Default value is 'master'.";
echo " Requirement: Optional";
echo "";
echo "--help";
echo " Print this command usage instruction.";
echo " Value: No value should be entered.";
echo " Requirement: Optional";
echo "";
}
# Handle arguments
if [[ "$#" -gt 0 ]]; then
case "$1" in
"--pwd")
password=$2;
shift;
shift;
;;
"--default-branch")
default_branch=$2;
shift;
shift;
;;
"--help")
print_usage;
exit 0;
;;
*)
echo "Error: Invalid argument $2.";
exit 1;
;;
esac;
else
echo "Error: Missing argument(s).";
print_usage;
exit 1;
fi;
if [[ "${password}" == "" ]]; then
echo "Error: Please enter a password.";
print_usage;
exit 1;
fi;
if [[ "${default_branch}" == "" ]]; then
echo "Error: Please enter a default branch name";
print_usage;
exit 1;
fi;
if [[ "${default_branch}" == "master" ]]; then
echo "";
echo "NOTE: Using 'master' as the default branch name.";
echo "";
fi;
# Install dependencies
sudo apt-get update;
sudo apt-get install -y git openssh-server net-tools;
# Create new user 'git' (for security)
sudo useradd --create-home -d /home/git --user-group --shell /bin/bash git;
# Set password for user 'git'
echo git:"${password}" | sudo chpasswd;
# Create directory for repositories
sudo mkdir /srv/git;
sudo chown -R git:git /srv/git;
# Configure the default branch for Git to use when a repository is created by the user 'git'
printf "[init]\n\tdefaultBranch = ${default_branch}\n" > /home/git/.gitconfig;
chown git:git /home/git/.gitconfig;
# Post-install instructions
echo "";
echo "Setup successful!";
echo "A Git server has been set up with a new user and group called 'git'.";
echo "Repositories have to be stored at /srv/git.";
echo "Password for user 'git': ${password}";
echo "SSH access: ssh git@$(hostname)";
echo "Server IP: $(hostname -I)";
echo "";
echo "For further instructions, please refer to https://github.com/HarshKapadia2/git-server/blob/main/README.md .";
echo "";