Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
frankcorneliusmartin committed Jan 10, 2024
1 parent 13157ec commit 8f06447
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 72 deletions.
145 changes: 75 additions & 70 deletions create-node.sh
Original file line number Diff line number Diff line change
@@ -1,89 +1,94 @@
#! /bin/bash

source $SCRIPT_DIR/utils.sh
CONFIG_FILE=$HOME/.config/vantage6/node/blueberry.yaml

# Create config dir
print_step "Creating config dir"
mkdir -p $HOME/.config

# Create config file
print_step "Creating config file"
echo -n " ? Please enter the API key: "; read -r API_KEY

# vantage6 node settings
export API_KEY=$API_KEY
export TASK_DIR=$HOME/tasks

mkdir -p $TASK_DIR

# OMOP settings
export OMOP_HOST="omop"
export OMOP_PORT=5432

export OMOP_DATABASE="postgres"
export OMOP_USER="postgres"
export OMOP_PASSWORD="postgres"
export OMOP_CDM_SCHEMA="cmd"
export OMOP_RESULT_SCHEMA="result"

# Check if the vantage6-node user already exists
print_step "Checking if the vantage6-node user already exists"
NEW_USER="vantage6-node"
if id -u "vantage6-node" >/dev/null 2>&1; then
print_warning "The vantage6-node user already exists"
else
print_step "Creating new user: $NEW_USER"
sudo useradd $NEW_USER

# Set password for the new user
PASSWORD=$(openssl rand -base64 16)
echo "$NEW_USER:$PASSWORD" | sudo chpasswd
WRITE_CONFIG_FILE=true
if [ -f "$CONFIG_FILE" ]; then
print_warning "Config file already exists at $CONFIG_FILE"
if confirm "Do you want to overwrite the config file?"; then
print_step "Overwriting the config file"
else
print_step "Using the existing config file"
WRITE_CONFIG_FILE=false
fi
fi

if [ "$WRITE_CONFIG_FILE" = true ]; then

print_step "Executing some steps as sudo user"
source $SCRIPT_DIR/create-ssh-user.sh
# Create config dir
print_step "Creating config dir"
mkdir -p $HOME/.config

# Tunnel settings
print_step "Setting tunnel settings"
export TUNNEL_HOSTNAME=$OMOP_HOST
export SSH_HOST=$(ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1)
export SSH_PORT=22
print_step "SSH_HOST: $SSH_HOST, SSH_PORT: $SSH_PORT"
# Create config file
print_step "Creating config file"
echo -n " ? Please enter the API key: "; read -r API_KEY

# vantage6 node settings
export API_KEY=$API_KEY
export TASK_DIR=$HOME/tasks

if [ -f "/etc/ssh/ssh_host_rsa_key.pub" ]; then
export SSH_HOST_FINGERPRINT=$(cat /etc/ssh/ssh_host_rsa_key.pub)
else
print_error "File /etc/ssh/ssh_host_rsa_key.pub does not exist."
print_error "Is openssh-server installed and running?"
fi
mkdir -p $TASK_DIR

export SSH_USERNAME=$NEW_USER
export SSH_KEY=$PRIVATE_KEY_FILE
print_step "SSH_KEY: $SSH_KEY"
# OMOP settings
export OMOP_HOST="omop"
export OMOP_PORT=5432

export TUNNEL_BIND_IP="0.0.0.0"
export TUNNEL_BIND_PORT=$OMOP_PORT
export OMOP_DATABASE="postgres"
export OMOP_USER="postgres"
export OMOP_PASSWORD="postgres"
export OMOP_CDM_SCHEMA="cmd"
export OMOP_RESULT_SCHEMA="result"

export TUNNEL_REMOTE_IP="127.0.0.1"
export TUNNEL_REMOTE_PORT=5432
print_step "TUNNEL_REMOTE_PORT: $TUNNEL_REMOTE_PORT"
# Check if the vantage6-node user already exists
print_step "Checking if the vantage6-node user already exists"
NEW_USER="vantage6-node"
if id -u "vantage6-node" >/dev/null 2>&1; then
print_warning "The vantage6-node user already exists"
else
print_step "Creating new user: $NEW_USER"
sudo useradd $NEW_USER

# # Create the config file
print_step "Creating the config file"
mkdir -p $HOME/.config/vantage6/node
CONFIG_FILE=$HOME/.config/vantage6/node/blueberry.yaml
# Set password for the new user
PASSWORD=$(openssl rand -base64 16)
echo "$NEW_USER:$PASSWORD" | sudo chpasswd
fi

if [ -f "$HOME/.config/vantage6/node/blueberry.yml" ]; then
print_warning "Config file already exists at $CONFIG_FILE"
if confirm "Do you want to overwrite the config file?"
then
print_step "Overwriting the config file"
create_config_file $SCRIPT_DIR $CONFIG_FILE

print_step "Executing some steps as sudo user"
source $SCRIPT_DIR/create-ssh-user.sh

# Tunnel settings
print_step "Setting tunnel settings"
export TUNNEL_HOSTNAME=$OMOP_HOST
export SSH_HOST=$(ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1)
export SSH_PORT=22
print_step "SSH_HOST: $SSH_HOST, SSH_PORT: $SSH_PORT"


if [ -f "/etc/ssh/ssh_host_rsa_key.pub" ]; then
export SSH_HOST_FINGERPRINT=$(cat /etc/ssh/ssh_host_rsa_key.pub)
else
print_error "File /etc/ssh/ssh_host_rsa_key.pub does not exist."
print_error "Is openssh-server installed and running?"
fi
else

export SSH_USERNAME=$NEW_USER
export SSH_KEY=$PRIVATE_KEY_FILE
print_step "SSH_KEY: $SSH_KEY"

export TUNNEL_BIND_IP="0.0.0.0"
export TUNNEL_BIND_PORT=$OMOP_PORT

export TUNNEL_REMOTE_IP="127.0.0.1"
export TUNNEL_REMOTE_PORT=5432
print_step "TUNNEL_REMOTE_PORT: $TUNNEL_REMOTE_PORT"

# # Create the config file
print_step "Creating the config file"
mkdir -p $HOME/.config/vantage6/node

print_step "Creating the vantage6 config file"
create_config_file $SCRIPT_DIR $CONFIG_FILE
fi


2 changes: 1 addition & 1 deletion install-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ print_header "Creating vantage6-node"
source $SCRIPT_DIR/create-node.sh

print_header "Post installation steps"
if confirm "Do you want to create a cronjob to automatically start the vantage6-node on boot?"; then
if confirm "Add cronjob to automatically start the vantage6-node on boot?"; then
source $SCRIPT_DIR/create-cronjob.sh
fi

Expand Down
3 changes: 2 additions & 1 deletion utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ print_outro(){

confirm() {
echo -e -n "\e[32m ? $1 (y/n) \e[0m"
read response
read -n1 response
echo
case "$response" in
[yY][eE][sS]|[yY])
true
Expand Down

0 comments on commit 8f06447

Please sign in to comment.