From 8f06447d039e7fc0f8370ae7701c07b4102e7202 Mon Sep 17 00:00:00 2001 From: "F.C. Martin" Date: Wed, 10 Jan 2024 12:18:40 +0100 Subject: [PATCH] Minor updates --- create-node.sh | 145 +++++++++++++++++++++++++------------------------ install-all.sh | 2 +- utils.sh | 3 +- 3 files changed, 78 insertions(+), 72 deletions(-) diff --git a/create-node.sh b/create-node.sh index d6ab37c..835b7b8 100644 --- a/create-node.sh +++ b/create-node.sh @@ -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 + diff --git a/install-all.sh b/install-all.sh index d9b3bb8..c215af8 100644 --- a/install-all.sh +++ b/install-all.sh @@ -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 diff --git a/utils.sh b/utils.sh index ec33059..9eaf8ca 100644 --- a/utils.sh +++ b/utils.sh @@ -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