-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
.ssh.sh
56 lines (51 loc) · 1.49 KB
/
.ssh.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
#!/bin/sh
if [ -d ~/.ssh ]; then
if mountpoint ~/.ssh | grep -q "is a mountpoint"; then
# ~/.ssh is a bind mount from the host
return 0;
fi
/bin/ls -a /mnt/ssh 2>/dev/null > /tmp/ls_mnt_ssh
/bin/ls -a ~/.ssh 2>/dev/null > /tmp/ls_ssh
/bin/ls -a /tmp/.ssh 2>/dev/null > /tmp/ls_tmp_ssh
if [ -d /mnt/ssh ] && [ -z "$(comm -3 /tmp/ls_mnt_ssh /tmp/ls_ssh)" ]; then
# /mnt/ssh and ~/.ssh are the same in terms of file names.
rm /tmp/ls_mnt_ssh
rm /tmp/ls_ssh
rm /tmp/ls_tmp_ssh
return 0;
fi
if [ -d /tmp/.ssh ] && [ -z "$(comm -3 /tmp/ls_tmp_ssh /tmp/ls_ssh)" ]; then
# Retro-compatibility: /tmp/.ssh and ~/.ssh are the same in terms of file names.
rm /tmp/ls_mnt_ssh
rm /tmp/ls_ssh
rm /tmp/ls_tmp_ssh
return 0;
fi
rm /tmp/ls_mnt_ssh
rm /tmp/ls_ssh
rm /tmp/ls_tmp_ssh
fi
if [ -d /tmp/.ssh ]; then
# Retro-compatibility
echo "Copying content of /tmp/.ssh to ~/.ssh"
mkdir -p ~/.ssh
cp -r /tmp/.ssh/* ~/.ssh/
chmod 600 ~/.ssh/*
chmod 644 ~/.ssh/*.pub > /dev/null 2>&1
return 0
fi
if [ ! -d /mnt/ssh ]; then
echo "No bind mounted ssh directory found (~/.ssh, /tmp/.ssh, /mnt/ssh), exiting"
return 0
fi
if [ "$(stat -c '%U' /mnt/ssh)" != "UNKNOWN" ]; then
echo "Unix host detected, symlinking /mnt/ssh to ~/.ssh"
rm -r ~/.ssh
ln -s /mnt/ssh ~/.ssh
return 0
fi
echo "Windows host detected, copying content of /mnt/ssh to ~/.ssh"
mkdir -p ~/.ssh
cp -rf /mnt/ssh/* ~/.ssh/
chmod 600 ~/.ssh/*
chmod 644 ~/.ssh/*.pub > /dev/null 2>&1