-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitstrap.sh
More file actions
173 lines (144 loc) · 4.73 KB
/
gitstrap.sh
File metadata and controls
173 lines (144 loc) · 4.73 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/bash
# Banner
B=[][][][]
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
echo "$B OS is $OS"
if [[ $OS == *"opensuse"* ]]; then
INSTALLCMD="zypper install -y"
else
INSTALLCMD="apt -y install"
fi
echo $INSTALLCMD
else
echo "$B /etc/os-release not found, can't determine OS so using apt"
INSTALLCMD="apt -y install"
fi
if [ -z "$1" ]; then
echo "$B Enter Github email address as command line parameter"
exit
else
GITEMAIL=$1
echo "$B GITEMAIL is $GITEMAIL"
fi
if [ ! -x "$(command -v "git")" ]; then
echo "$B Git not found, installing git"
sudo $INSTALLCMD git
fi
if [ ! -x "$(command -v "sshd")" ]; then
echo "$B OpenSSH not found, installing openssh-server"
sudo $INSTALLCMD openssh-server
fi
echo "$B Enabling ssh server"
if (systemctl is-active --quiet sshd.service); then
echo "$B SSHD is already started"
else
sudo systemctl enable --now sshd.service
sudo systemctl status sshd.service
fi
SETGIT=`which git`
echo "$B Using $SETGIT"
SETOS=`uname | tr '[:upper:]' '[:lower:]'`
echo "$B OS is $SETOS"
SETGITNAME="$USER@$HOSTNAME"
echo "$B GITNAME is $SETGITNAME"
# ssh key setup
if [ ! -f $HOME/.ssh/github ]; then
echo "$B Attempting to copy key from another host"
echo "$B Requires root login via password, run this on source host:"
echo "sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config"
echo "systemctl restart sshd"
echo " "
mkdir -p $HOME/.ssh 2>/dev/null
scp -o StrictHostKeyChecking=accept-new -OT root@10.0.0.4:".ssh/github .ssh/github.pub .ssh/config" $HOME/.ssh/
chmod 600 $HOME/.ssh/github
chmod 644 $HOME/.ssh/github.pub
chmod 644 $HOME/.ssh/config
echo "$B Now change source host ssh config back"
echo "sed -i 's/PermitRootLogin yes/#PermitRootLogin prohibit-password/' sshd_config"
echo "systemctl restart sshd"
fi
if [ ! -d $HOME/.ssh ]; then
echo "$B Creating ~/.ssh because it does not exist"
mkdir $HOME/.ssh
chmod 700 $HOME/.ssh
fi
if [ ! -f $HOME/.ssh/github ]; then
echo "$B Paste github PRIVATE key, waiting 3s"
sleep 2
nano $HOME/.ssh/github
chmod 600 $HOME/.ssh/github
fi
if [ ! -f $HOME/.ssh/github.pub ]; then
echo "$B Paste github PUBLIC key, waiting 3s"
sleep 2
nano $HOME/.ssh/github.pub
chmod 644 $HOME/.ssh/github.pub
fi
if ! grep -q "Host github.com" $HOME/.ssh/config; then
cat >> $HOME/.ssh/config<< EOF
Host github.com
User c0f
IdentityFile = ~/.ssh/github
Hostname ssh.github.com
Port 443
Host *
AddKeysToAgent yes
EOF
# echo "$B Paste github config to ~/.ssh/config, waiting 7s"
# echo "Host github.com"
# echo " User c0f"
# echo " IdentityFile = ~/.ssh/github"
# echo " Hostname ssh.github.com"
# echo " Port 443"
# echo "Host *"
# echo " AddKeysToAgent yes"
# sleep 7
# nano $HOME/.ssh/config
chmod 644 $HOME/.ssh/config
fi
echo "$B Connecting to Github via ssh to add to known hosts"
ssh -o StrictHostKeyChecking=accept-new -T git@github.com
# git repo setup
if [ ! -f $HOME/.gitcfg/config ]; then
echo "$B Creating new repo"
git init --bare $HOME/.gitcfg
fi
if ! grep -q "alias gitc='$SETGIT --git-dir=$HOME/.gitcfg/ --work-tree=$HOME'" $HOME/.bashrc; then
echo "$B Adding gitc alias to .bashrc"
echo "alias gitc='$SETGIT --git-dir=$HOME/.gitcfg/ --work-tree=$HOME'" >> $HOME/.bashrc
fi
alias gitc='$SETGIT --git-dir=$HOME/.gitcfg/ --work-tree=$HOME'
shopt -s expand_aliases
if [ ! -d $HOME/.gitcfg ]; then
echo ".gitcfg" >> $HOME/.gitignore
fi
echo "$B Changing settings"
gitc config --local status.showUntrackedFiles no
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=7200'
git config --global user.email "$SETGITEMAIL"
git config --global user.name "$SETGITNAME"
git config --global user.username c0f
echo "$B Remote will be ssh://git@github.com/c0f/$SETOS.git"
gitc remote add origin ssh://git@github.com/c0f/$SETOS.git
echo "$B Git Config"
gitc config --list | cat
echo "$B Git Remote Settings"
gitc remote -v
echo "$B Git Status"
gitc status
echo "$B Delete these files that might prevent first pull"
echo "rm .bashrc .bash_profile .gitignore .profile .Xdefaults .xscreensaver"
echo "rm .config/kateschemarc .config/kglobalshortcutsrc .config/kwinrc .config/konsolerc .config/gwenviewrc .config/katerc"
echo "rm .config/openbox/lxqt-rc.xml .config/pcmanfm-qt/lxqt/settings.conf .config/qterminal.org/qterminal.ini .config/lxterminal/lxterminal.conf"
echo "rm .config/xfce4/xfconf/xfce-perchannel-xml/thunar.xml"
echo "$B Use this alias, then gitc clone"
echo "alias gitc='$SETGIT --git-dir=$HOME/.gitcfg/ --work-tree=$HOME'"
echo "gitc pull origin master"
echo " "
echo "$B Run this command on other hosts to copy remote user keys to ${USERNAME}'s authorized_keys on this host"
MYIP=$(ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}')
echo "ssh-copy-id ${USER}@$MYIP"
echo " "