blob: 5e59b2d0b86c5a1865a3378849f83e8063b66847 [file] [log] [blame]
Maciej Strzelczyk19614612021-07-19 16:28:01 +02001#!/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]
18apt-get update
19apt-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
24IMAGE_URL=$(curl http://metadata/computeMetadata/v1/instance/attributes/url -H "Metadata-Flavor: Google")
25TEXT=$(curl http://metadata/computeMetadata/v1/instance/attributes/text -H "Metadata-Flavor: Google")
26CS_BUCKET=$(curl http://metadata/computeMetadata/v1/instance/attributes/bucket -H "Metadata-Flavor: Google")
27
28mkdir image-output
29cd image-output
30wget $IMAGE_URL
31convert * -pointsize 30 -fill white -stroke black -gravity center -annotate +10+40 "$TEXT" output.png
32
33# Create a Google Cloud Storage bucket.
34gsutil mb gs://$CS_BUCKET
35
36# Store the image in the Google Cloud Storage bucket and allow all users
37# to read it.
38gsutil cp -a public-read output.png gs://$CS_BUCKET/output.png
39
40# [END compute_apiary_startup_script]