Maciej Strzelczyk | 1961461 | 2021-07-19 16:28:01 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2015 Google Inc. All Rights Reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # [START compute_apiary_startup_script] |
| 18 | apt-get update |
| 19 | apt-get -y install imagemagick |
| 20 | |
| 21 | # Use the metadata server to get the configuration specified during |
| 22 | # instance creation. Read more about metadata here: |
| 23 | # https://cloud.google.com/compute/docs/metadata#querying |
| 24 | IMAGE_URL=$(curl http://metadata/computeMetadata/v1/instance/attributes/url -H "Metadata-Flavor: Google") |
| 25 | TEXT=$(curl http://metadata/computeMetadata/v1/instance/attributes/text -H "Metadata-Flavor: Google") |
| 26 | CS_BUCKET=$(curl http://metadata/computeMetadata/v1/instance/attributes/bucket -H "Metadata-Flavor: Google") |
| 27 | |
| 28 | mkdir image-output |
| 29 | cd image-output |
| 30 | wget $IMAGE_URL |
| 31 | convert * -pointsize 30 -fill white -stroke black -gravity center -annotate +10+40 "$TEXT" output.png |
| 32 | |
| 33 | # Create a Google Cloud Storage bucket. |
| 34 | gsutil mb gs://$CS_BUCKET |
| 35 | |
| 36 | # Store the image in the Google Cloud Storage bucket and allow all users |
| 37 | # to read it. |
| 38 | gsutil cp -a public-read output.png gs://$CS_BUCKET/output.png |
| 39 | |
| 40 | # [END compute_apiary_startup_script] |