|
@@ -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"
|
|
|
+ # 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
|
|
|
|
|
|
- # 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"
|
|
|
|
|
|
- rm -f "$temp_file"
|
|
|
- fi
|
|
|
}
|
|
|
|
|
|
while true; do
|