blob: 179e95b4edc78182786d420bce470c050536eefe [file] [log] [blame]
#!/bin/bash
# Copyright 2021 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
cat << EOF
###############################################################################
IMPORTANT: Please read below information
###############################################################################
Setting up Satlab requires special privileges, you need access to
serviceaccount and keys to access docker images and other configuration files.
This script will authenticate the user to access the required artifacts.
The following the are steps this script executes:
1. Authenticate user using GCloud SDK(uses gcloud-sdk docker container),
when prompted please use your google.com account
2. Ask for service account, please follow (go/satlab-manual) to create
the service account if needed.
3. Get required service account and keys from cloud application.
4. Finally reboots the chromebox. (You must restart the chromebox inorder to
finish the satlab setup)
###############################################################################
EOF
while true; do
read -p "Do you want to continue with the Satlab setup(y/n)?" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
SATLAB_SERIVCE_ACCOUNT=satlab-prototype@chromeos-service-accounts-dev.iam.gserviceaccount.com
KEYS_FOLDER=/home/satlab/keys
GCLOUD="docker run --rm -ti -a stdout -v satlab_keys:${KEYS_FOLDER} -v gcloud:/root/.config/gcloud google/cloud-sdk:slim"
echo "******* SATLAB Setup Starting..... *********"
echo
echo "Authenticating the user, please follow the instructions... ###"
echo
${GCLOUD} gcloud auth login
if [ "$?" -ne 0 ]; then
echo "Failed to authenticate the user, you must use your @google.com account. Please try again!"
exit
fi
# TODO (anhdle): Enable mutilple service accounts when easier user workflow is available
# read -p "Please specify the service account: " sa
# echo "Create and download service account key..."
# ${GCLOUD} gcloud iam service-accounts keys create "${KEYS_FOLDER}/satlab_service_account.json" --iam-account="$sa"
# if [ "$?" -ne 0 ]; then
# echo "Failed to create service account key, please try again!"
# exit
# fi
echo
echo "Generating service account key..."
echo
${GCLOUD} gcloud iam service-accounts keys create "${KEYS_FOLDER}/satlab_service_account.json" --iam-account="$SATLAB_SERIVCE_ACCOUNT"
echo "Configuring Satlab Privileges successful, please reboot"
echo
while true; do
read -p "Do you want to reboot now(y/n)?" yn
case $yn in
[Yy]* ) reboot;;
[Nn]* ) echo "You MUST restart to apply start Satlab"
exit;;
* ) echo "Please answer yes or no.";;
esac
done