|
1 | 1 | #!/bin/bash |
2 | 2 | echo "----------------------------------------------" |
3 | | -echo "Running Phala Cloud Pre-Launch Script v0.0.10" |
| 3 | +echo "Running Phala Cloud Pre-Launch Script v0.0.11" |
4 | 4 | echo "----------------------------------------------" |
5 | 5 | set -e |
6 | 6 |
|
@@ -160,19 +160,29 @@ else |
160 | 160 | echo "Root password already set; no changes." |
161 | 161 | fi |
162 | 162 |
|
| 163 | +mkdir -p /home/root/.ssh |
163 | 164 | if [[ -n "$DSTACK_ROOT_PUBLIC_KEY" ]]; then |
164 | | - mkdir -p /home/root/.ssh |
165 | 165 | echo "$DSTACK_ROOT_PUBLIC_KEY" > /home/root/.ssh/authorized_keys |
166 | 166 | unset $DSTACK_ROOT_PUBLIC_KEY |
167 | 167 | echo "Root public key set" |
168 | 168 | fi |
169 | 169 | if [[ -n "$DSTACK_AUTHORIZED_KEYS" ]]; then |
170 | | - mkdir -p /home/root/.ssh |
171 | 170 | echo "$DSTACK_AUTHORIZED_KEYS" > /home/root/.ssh/authorized_keys |
172 | 171 | unset $DSTACK_AUTHORIZED_KEYS |
173 | 172 | echo "Root authorized_keys set" |
174 | 173 | fi |
175 | 174 |
|
| 175 | +if [[ -f /dstack/user_config ]] && jq empty /dstack/user_config 2>/dev/null; then |
| 176 | + if [[ $(jq 'has("ssh_authorized_keys")' /dstack/user_config 2>/dev/null) == "true" ]]; then |
| 177 | + jq -j '.ssh_authorized_keys' /dstack/user_config >> /home/root/.ssh/authorized_keys |
| 178 | + # Remove duplicates if there are multiple keys |
| 179 | + if [[ $(cat /home/root/.ssh/authorized_keys | wc -l) -gt 1 ]]; then |
| 180 | + sort -u /home/root/.ssh/authorized_keys > /home/root/.ssh/authorized_keys.tmp |
| 181 | + mv /home/root/.ssh/authorized_keys.tmp /home/root/.ssh/authorized_keys |
| 182 | + fi |
| 183 | + echo "Set root authorized_keys from user preferences, total" $(cat /home/root/.ssh/authorized_keys | wc -l) "keys" |
| 184 | + fi |
| 185 | +fi |
176 | 186 |
|
177 | 187 | if [[ -S /var/run/dstack.sock ]]; then |
178 | 188 | export DSTACK_APP_ID=$(curl -s --unix-socket /var/run/dstack.sock http://dstack/Info | jq -j .app_id) |
|
0 commit comments