|
3 | 3 | # Enable strict mode (exit on error). |
4 | 4 | set -e |
5 | 5 |
|
6 | | -# Copy all ssh keys to the home directory, as the temporary directory will be |
7 | | -# cleared within seconds afters starting the container. |
8 | | -cp -R /tmp/.ssh/* /root/.ssh/ |
| 6 | +# The /tmp/.ssh directory is used to pass SSH keys to the container. If it is empty |
| 7 | +# or does not exist, no SSH keys will be imported. |
| 8 | +if [ -d "/tmp/.ssh" ] && [ "$(ls -A /tmp/.ssh 2>/dev/null)" ]; then |
9 | 9 |
|
10 | | -# Ensure proper line breaks and line endings in all SSH key files. |
11 | | -find /root/.ssh -type f -name "id_*" -exec dos2unix -q {} + |
| 10 | + # Copy all SSH keys from the temporary directory to the root's SSH directory. |
| 11 | + cp -R /tmp/.ssh/* /root/.ssh/ |
12 | 12 |
|
13 | | -# Set the required permissions for SSH key files. |
14 | | -chmod 700 /root/.ssh |
15 | | -find /root/.ssh/ -type f -name "id_*" -exec chmod 600 {} + |
16 | | -find /root/.ssh/ -type f -name "id_*.pub" -exec chmod 644 {} + |
| 13 | + # Ensure proper line breaks and line endings in all SSH key files. |
| 14 | + find /root/.ssh -type f -name "id_*" -exec dos2unix -q {} + |
| 15 | + |
| 16 | + # Set the required permissions for SSH key files. |
| 17 | + find /root/.ssh/ -type f -name "id_*" -exec chmod 600 {} + |
| 18 | + find /root/.ssh/ -type f -name "id_*.pub" -exec chmod 644 {} + |
17 | 19 |
|
18 | | -# Start the ssh agent and add the keys to the current session. |
19 | | -eval "$(ssh-agent)" > /dev/null |
20 | | -find /root/.ssh -type f -name "id_*" ! -name "*.pub" -exec ssh-add -q {} \; |
| 20 | + # Start the ssh agent and add the keys to the current session. |
| 21 | + eval "$(ssh-agent)" > /dev/null |
| 22 | + find /root/.ssh -type f -name "id_*" ! -name "*.pub" -exec ssh-add -q {} \; |
| 23 | +fi |
| 24 | + |
| 25 | +# Set the required permissions for the SSH directory. |
| 26 | +chmod 700 /root/.ssh |
21 | 27 |
|
22 | 28 | # Execute the command passed as arguments. |
23 | 29 | exec "$@" |
0 commit comments