I want to run a local bash script on a remote machine to install and sets up dokku and its plugins. (ssh root@remotehost 'bash -s' < dokku.sh) The script requires a few config values like AWS_BACKUP_ACCESS etc. Those variables are stored in a separate json file, like this:
/home/project/env.json
{
"DB_NAME": "mydb",
"APP_NAME": "web",
"AWS_BACKUP_ACCESS": "xxx",
"AWS_BACKUP_SECRET": "yyy",
}
dokku.sh
#!/bin/bash
json_file="/home/project/env.json"
# export all key values from env.json to globa env
for s in $(cat $json_file | jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" ); do
export $s;
done
wget https://raw.githubusercontent.com/dokku/dokku/v0.25.7/bootstrap.sh;
sudo DOKKU_TAG=v0.25.7 bash bootstrap.sh
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres
dokku postgres:create "$DB_NAME"
dokku postgres:link "$DB_NAME" "$APP_NAME"
# use the Backup IAM profile
dokku postgres:backup-auth "$DB_NAME" "$AWS_BACKUP_ACCESS" "$AWS_BACKUP_SECRET" "$AWS_DEFAULT_REGION"
My question is how to make the following part works when running the script on a remote server since the file /home/project/env.json is stored locally:
json_file="/home/project/env.json"
# export all key values from env.json to globa env
for s in $(cat $json_file | jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" ); do
export $s;
done