1#!/bin/bash 2# 3# Script for operators to create formated images. 4# first arg is the size of a disk in GB. 5 6set -x 7set -o errexit 8 9if [ "$#" -ne 1 ]; then 10 echo "The argument should be the size of a disk in GB" 11 exit 2 12fi 13 14PROJECT=android-treehugger 15ZONE=us-central1-f 16DISK_NAME="extradisk-instance-${1}gb" 17IMAGE_NAME="extradisk-image-${1}gb" 18DEV_FILE="/dev/sdc" 19 20gcloud compute disks create "${DISK_NAME}" --zone=${ZONE} --project=${PROJECT} --size="${1}GB" 21gcloud compute instances attach-disk instance-disk-creation --disk "${DISK_NAME}" --zone=${ZONE} --project=${PROJECT} 22 23gcloud compute ssh instance-disk-creation --zone=${ZONE} --project=${PROJECT} --command "sudo mkfs.ext4 -F ${DEV_FILE}" 24gcloud compute ssh instance-disk-creation --zone=${ZONE} --project=${PROJECT} --command "sudo mount -o discard,defaults ${DEV_FILE} /mnt" 25gcloud compute ssh instance-disk-creation --zone=${ZONE} --project=${PROJECT} --command "ls /mnt" 26gcloud compute ssh instance-disk-creation --zone=${ZONE} --project=${PROJECT} --command "sudo umount /mnt" 27 28gcloud compute instances detach-disk instance-disk-creation --disk "${DISK_NAME}" --zone=${ZONE} --project=${PROJECT} 29gcloud compute images create "${IMAGE_NAME}" --source-disk-zone=${ZONE} --source-disk "${DISK_NAME}" --project=${PROJECT} 30gcloud compute disks delete "${DISK_NAME}" --zone=${ZONE} --project=${PROJECT} 31echo "Done image ${IMAGE_NAME} is ready." 32