|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -# Define the password file location |
4 | | -PASSWORD_FILE="/usr/start/user_password.txt" |
5 | | - |
6 | | -if [ ! -z "${SEALOS_DEVBOX_NEED_INIT}" ] && [ "${SEALOS_DEVBOX_NEED_INIT}" == "true" ]; then |
7 | | - if [ -d "/home/devbox/.ssh" ]; then |
8 | | - cd /home/devbox/.ssh |
9 | | - rm -rf ./* |
10 | | - fi |
11 | | - if [ -f "/usr/start/user_password.txt" ]; then |
12 | | - rm /usr/start/user_password.txt |
13 | | - fi |
14 | | -fi |
15 | | - |
16 | | -# Check if the password file exists |
17 | | -if [ ! -f "${PASSWORD_FILE}" ]; then |
18 | | - # If the password file doesn't exist, check if USER_PASSWORD is already set |
19 | | - if [ -z "${SEALOS_DEVBOX_PASSWORD}" ]; then |
20 | | - # If USER_PASSWORD is not set, generate a random 8-character password |
21 | | - SEALOS_DEVBOX_PASSWORD=$(< /dev/urandom tr -dc A-Za-z0-9 | head -c8) |
22 | | - fi |
23 | | - # Save the generated or existing USER_PASSWORD to the password file |
24 | | - touch "${PASSWORD_FILE}" |
25 | | - # Set the password for the 'sealos' user |
26 | | - echo "devbox:${SEALOS_DEVBOX_PASSWORD}" | sudo chpasswd |
27 | | - # Display the password for logging purposes (optional) |
28 | | - echo "SEALOS_DEVBOX_PASSWORD=${SEALOS_DEVBOX_PASSWORD}" |
29 | | -fi |
30 | | - |
31 | | -if [ -f /usr/start/.ssh/id.pub ]; then |
32 | | - public_key=$(cat /usr/start/.ssh/id.pub) |
33 | | - if ! grep -qF "$public_key" /home/devbox/.ssh/authorized_keys 2>/dev/null; then |
34 | | - mkdir -p /home/devbox/.ssh |
35 | | - echo "$public_key" >> /home/devbox/.ssh/authorized_keys |
36 | | - echo "Public key successfully added to authorized_keys" |
37 | | - fi |
38 | | -fi |
39 | | - |
40 | 3 | if [ ! -z "${SEALOS_DEVBOX_NAME}" ]; then |
41 | 4 | echo "${SEALOS_DEVBOX_NAME}">/etc/hostname |
42 | 5 | fi |
|
0 commit comments