Skip to content

Commit

Permalink
updating script to add existing labels
Browse files Browse the repository at this point in the history
  • Loading branch information
aronchick committed Oct 19, 2024
1 parent 193d16e commit 5c1ef84
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
24 changes: 24 additions & 0 deletions internal/clouds/general/100_install_bacalhau.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@

BACALHAU_INSTALL_ID=${BACALHAU_INSTALL_ID:-"BACA14A0-eeee-eeee-eeee-eeeeeeeeeeee"}

ensure_jq_installed() {
if ! command -v jq &> /dev/null; then
log "jq is not installed. Attempting to install..."
if command -v apt-get &> /dev/null; then
sudo apt-get update && sudo apt-get install -y jq
elif command -v yum &> /dev/null; then
sudo yum install -y jq
elif command -v dnf &> /dev/null; then
sudo dnf install -y jq
elif command -v brew &> /dev/null; then
brew install jq
else
log "Error: Unable to install jq. Please install it manually."
exit 1
fi
log "jq has been installed successfully."
else
log "jq is already installed."
fi
}

ensure_jq_installed

# Replace the last 12 characters of the BACALHAU_INSTALL_ID with random 12 characters
BACALHAU_INSTALL_ID=$(echo "${BACALHAU_INSTALL_ID}" | \
python3 -c "
Expand All @@ -14,3 +37,4 @@ print(new_id)
")

sudo curl -sSL https://get.bacalhau.org/install.sh?dl="${BACALHAU_INSTALL_ID}" | sudo bash

27 changes: 21 additions & 6 deletions internal/clouds/general/105_install_run_bacalhau.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
}
# Source the configuration file
if [ -f /etc/node-config ]; then
# shellcheck disable=SC1091
Expand All @@ -31,11 +32,28 @@ check_orchestrators() {
fi
}
get_current_labels() {
local config_json
config_json=$(bacalhau config list --output json)
if [ -z "$config_json" ]; then
log "Error: Failed to get Bacalhau configuration"
return 1
fi
local labels
labels=$(echo "$config_json" | jq -r '.[] | select(.Key == "Labels") | .Value | to_entries | map("\(.key)=\(.value)") | join(",")')
echo "$labels"
}
start_bacalhau() {
log "Starting Bacalhau..."
# Initialize an empty string for labels
LABELS=""
# Initialize labels with current labels from Bacalhau config
LABELS=$(get_current_labels)
if [ $? -ne 0 ]; then
log "Failed to get current labels. Proceeding with empty labels."
LABELS=""
fi
# Read each line from node-config
while IFS= read -r line
Expand All @@ -51,12 +69,9 @@ start_bacalhau() {
var_value=$(echo "$var_value" | tr -d '"')
# Append to LABELS string
LABELS="${LABELS}${var_name}=${var_value},"
LABELS="${LABELS:+$LABELS,}${var_name}=${var_value}"
done < /etc/node-config
# Remove the trailing comma
LABELS="${LABELS%,}"
# Print the labels for verification
echo "Constructed Labels:"
echo "$LABELS"
Expand Down

0 comments on commit 5c1ef84

Please sign in to comment.