mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-31 10:58:02 +00:00
eda167bb88
For some reason, it doesn't always execute. I haven't bothered figuring out why tho. >_>
61 lines
2.2 KiB
Bash
Executable File
61 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env nix-shell
|
|
#! nix-shell --pure -i bash -p nix git coreutils google-cloud-sdk
|
|
#
|
|
# This is a modified script `nixos/maintainers/scripts/gce/create-gce.sh' from
|
|
# `nixpkgs'.
|
|
#
|
|
# Licensed under MIT license
|
|
# Copyright (c) 2003-2022 Eelco Dolstra and the Nixpkgs/NixOS contributors
|
|
# 2022 Gabriel Arazas
|
|
#
|
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
# a copy of this software and associated documentation files (the
|
|
# "Software"), to deal in the Software without restriction, including
|
|
# without limitation the rights to use, copy, modify, merge, publish,
|
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
# permit persons to whom the Software is furnished to do so, subject to
|
|
# the following conditions:
|
|
#
|
|
# The above copyright notice and this permission notice shall be
|
|
# included in all copies or substantial portions of the Software.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
BUCKET_NAME="${BUCKET_NAME:-foodogsquared-operating-system-images-dumping-ground}"
|
|
TIMESTAMP="$(date +%Y%m%d%H%M)"
|
|
PACKAGE=plover-gce
|
|
DIRECTORY=gce-image
|
|
FORCE=0
|
|
export TIMESTAMP
|
|
|
|
nix build ".#$PACKAGE" -o "$DIRECTORY"
|
|
|
|
img_path=$(echo "$DIRECTORY"/*.tar.gz)
|
|
img_name=${IMAGE_NAME:-$(basename "$img_path")}
|
|
img_id=$(echo "$img_name" | sed 's|.raw.tar.gz$||;s|\.|-|g;s|_|-|g')
|
|
img_family=$(echo "$img_id" | cut -d - -f1-4)
|
|
|
|
if [ $FORCE -eq 1 ] || ! gsutil ls "gs://${BUCKET_NAME}/$img_name"; then
|
|
[ $FORCE -eq 1 ] && FORCE_ARG="--force"
|
|
|
|
gsutil cp "$img_path" "gs://${BUCKET_NAME}/$img_name"
|
|
|
|
gcloud compute images create \
|
|
"$img_id" \
|
|
--source-uri "gs://${BUCKET_NAME}/$img_name" \
|
|
--family="$img_family" "$FORCE_ARG"
|
|
|
|
gcloud compute images add-iam-policy-binding "$img_id" \
|
|
--member='allAuthenticatedUsers' \
|
|
--role='roles/compute.imageUser'
|
|
fi
|
|
|
|
# vi:ft=bash
|