-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.sh
executable file
·73 lines (69 loc) · 2.21 KB
/
setup.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
#!/usr/bin/env bash
CONFDIR="$HOME/configs"
FILES=`ls -A $CONFDIR | grep -v "setup.sh" | grep -v -e "\.git\b" | grep -v "README"`
echo $FILES;
for FILE in $FILES
do
if [ $FILE == 'README.md' ]; then
continue
fi
#Specific stuff for the auth key file:
if [ $FILE == 'authorized_keys' ]; then
#ensure ssh dir exists
if [ -d "$HOME/.ssh" ]; then
echo "ssh dir exists"
else
echo "no ssh dir, creating"
mkdir "$HOME/.ssh"
fi
#symlink exists:
if [ -L "$HOME/.ssh/authorized_keys" ]; then
echo "Simlink for authorized_keys already existed, skipping ..."
continue
fi
#We already have a file there
if [ -f "$HOME/.ssh/authorized_keys" ] && [ `diff "$HOME/.ssh/authorized_keys" "$CONFDIR/authorized_keys"|head -n1` ]; then
echo -e "The file $FILE already exists, here is the difference:"
diff "$HOME/.ssh/authorized_keys" "$CONFDIR/authorized_keys"
echo "\n\nDo you want to replace it with the new one?[y/n]"
read USERINPUT
#Its a bit confusing, but this says, if NOT 'y' then do
if [ "$USERINPUT" == "${USERINPUT#[Yy]}" ]; then
echo "Not replacing the authorized keys file"
continue
fi
fi
#If we have gotten here then we are good to do things
echo "Replacing/Adding new authorized key file..."
cd "$HOME/.ssh"
rm -i "$HOME/.ssh/authorized_keys"
ln -s "$HOME/configs/authorized_keys" "$HOME/.ssh/"
echo "Verifying permissions on .ssh dir"
chmod 0700 "$HOME/.ssh"
chmod 0600 "$CONFDIR/authorized_keys"
continue
fi
#if the symlink exists, don't worry anymore
if [ -L "$HOME/$FILE" ]; then
continue
fi
#If the file exists...
if [ -f "$HOME/$FILE" ];
then
if [ `diff "$CONFDIR/$FILE" "$HOME/$FILE"|head -n1` ];
then
#file already exists its up to you to fix it
echo -e "The file $FILE already exists, here is the difference:"
diff "$CONFDIR/$FILE" "$HOME/$FILE"
continue
else
echo -e "The file $FILE already exists but I didn't see any differences so I went ahead and replaced it with a symlink"
rm "$HOME/$FILE"
ln -s "$CONFDIR/$FILE" "$HOME/$FILE"
continue
fi
else
echo -e "I don't think anything existed so I'm adding $FILE"
ln -s "$CONFDIR/$FILE" "$HOME/$FILE"
fi
done