sh 在Ubuntu中安装和设置Google SDK工具
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 在Ubuntu中安装和设置Google SDK工具相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env bash
export SOURCE_FOLDER=/tmp
export DESTINATION_FOLDER=tmp
export BUCKET=backup_bucket
#echo "lalalalalala" > /tmp/lala.txt
# Service Account role: roles/storage.objectAdmin = Storage Object Admin
export KEY=Service_Account.json
export NEWUSER=mybackup
export CRON="00 10 * * *"
# setup new user environment
if id -u $NEWUSER > /dev/null 2>&1; then
useradd -s /bin/bash -m $NEWUSER
fi
export PRIVATE_KEY=/home/$NEWUSER/$KEY
cp ./$KEY $PRIVATE_KEY
chmod 400 $PRIVATE_KEY
export SSH_FOLDER=/home/$NEWUSER/.ssh && \
mkdir -p $SSH_FOLDER && \
chmod 700 $SSH_FOLDER && \
echo "Host *" > $SSH_FOLDER/config && \
echo " StrictHostKeyChecking no" >> $SSH_FOLDER/config && \
chmod 600 $SSH_FOLDER/config && \
chown -Rf $NEWUSER:$NEWUSER /home/$NEWUSER
# install requirements
apt-get update && apt-get install -y lsb-core curl ssh jq && \
export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" && \
echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \
apt-get update -y && apt-get install google-cloud-sdk -y
# gcloud activation
export CLIENT_EMAIL=$(jq '.client_email' $PRIVATE_KEY | cut -d "\"" -f 2)
export PROJECT_ID=$(jq '.project_id' $PRIVATE_KEY | cut -d "\"" -f 2)
sudo -H -u $NEWUSER -s bash gcloud auth activate-service-account $CLIENT_EMAIL --key-file=$PRIVATE_KEY --project=$PROJECT_ID
GSUTIL_COMMAND="/usr/bin/gsutil -m rsync -r $SOURCE_FOLDER gs://$BUCKET/$DESTINATION_FOLDER"
# cron job
export CRONTAB_FILE=/var/spool/cron/crontabs/$NEWUSER
echo "$CRON $GSUTIL_COMMAND" >> $CRONTAB_FILE
chmod 600 $CRONTAB_FILE
chown $NEWUSER:crontab $CRONTAB_FILE
echo "Running: sudo -H -u $NEWUSER -s bash $GSUTIL_COMMAND"
sudo -H -u $NEWUSER -s bash $GSUTIL_COMMAND
以上是关于sh 在Ubuntu中安装和设置Google SDK工具的主要内容,如果未能解决你的问题,请参考以下文章
在Ubuntu中安装和升级软件的利器:PPA
Ubuntu中安装和使用miniconda
Ubuntu中安装和配置 Java JDK,并卸载自带OpenJDK(以Ubuntu 14.04为例)
如何在 Eclipse 中安装和设置 Cucumber jar 文件以进行 WebDriver 测试
Ubuntu 命令教程全录
如何在Windows中安装和使用“make”?