diff --git a/docker/proxy/Dockerfile b/docker/proxy/Dockerfile index 5ce2a0d1..5cd11d54 100644 --- a/docker/proxy/Dockerfile +++ b/docker/proxy/Dockerfile @@ -9,7 +9,6 @@ COPY ./config/initproxy.conf /data/nginx/proxy_host/ #RUN ls /etc/s6-overlay/s6-rc.d/init_user #RUN touch /etc/s6-overlay/s6-rc.d/user/contents.d/init_user #RUN chmod -R 755 /etc/s6-overlay/s6-rc.d/init_user - COPY ./s6/init_user/init_user.sh /app/init_user.sh RUN chmod +x /app/init_user.sh CMD ["/bin/sh", "-c", "/app/init_user.sh && tail -f /dev/null"] \ No newline at end of file diff --git a/docker/proxy/s6/init_user/init_user.sh b/docker/proxy/s6/init_user/init_user.sh index 6d24dd91..d9fa1c0a 100644 --- a/docker/proxy/s6/init_user/init_user.sh +++ b/docker/proxy/s6/init_user/init_user.sh @@ -2,6 +2,7 @@ echo "Start to change nginxproxymanage users" +set +e username="help@websoft9.com" password=$(openssl rand -base64 16 | tr -d '/+' | cut -c1-16) token="" @@ -47,4 +48,6 @@ done echo "Save to credential" json="{\"username\":\"$username\",\"password\":\"$password\"}" -echo "$json" > "$cred_path" \ No newline at end of file +echo "$json" > "$cred_path" + +set -e \ No newline at end of file diff --git a/systemd/send_credentials.sh b/systemd/send_credentials.sh index 5652f329..d9491d18 100644 --- a/systemd/send_credentials.sh +++ b/systemd/send_credentials.sh @@ -9,31 +9,29 @@ counter=1 portainer_username="admin" copy_credential() { + source_container=$1 source_path=$2 destination_container=$3 destination_path=$4 - if docker exec "$destination_container" [ -f "$destination_path" ]; then - printf "%s already exists\n" "$destination_path" + temp_file=$(mktemp) + docker cp "$source_container:$source_path" "$temp_file" + + # Check if temp_file is JSON format + if jq -e . >/dev/null 2>&1 <<< "$(cat "$temp_file")"; then + # If it is JSON format, use it directly + docker cp "$temp_file" "$destination_container:$destination_path" else - temp_file=$(mktemp) - docker cp "$source_container:$source_path" "$temp_file" - - # Check if temp_file is JSON format - if jq -e . >/dev/null 2>&1 <<< "$(cat "$temp_file")"; then - # If it is JSON format, use it directly - docker cp "$temp_file" "$destination_container:$destination_path" - else - # If it is not JSON format, get the content and convert it to JSON - content=$(cat "$temp_file") - json="{\"username\":\"$portainer_username\",\"password\":\"$content\"}" - echo "$json" > "$temp_file" - docker cp "$temp_file" "$destination_container:$destination_path" - fi - - rm -f "$temp_file" + # If it is not JSON format, get the content and convert it to JSON + content=$(cat "$temp_file") + json="{\"username\":\"$portainer_username\",\"password\":\"$content\"}" + echo "$json" > "$temp_file" + docker cp "$temp_file" "$destination_container:$destination_path" fi + + rm -f "$temp_file" + } while true; do