Skip to content

Commit

Permalink
backup just in case
Browse files Browse the repository at this point in the history
  • Loading branch information
Will K committed Sep 12, 2024
1 parent 97095fc commit 22d2565
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ run_command() {
fi
}

# Function to back up existing files
backup_if_exists() {
local file=$1
if [ -f "$file" ]; then
local backup_file="${file}.bak.$(date +%Y%m%d%H%M%S)"
echo "Backing up $file to $backup_file"
run_command "cp $file $backup_file"
fi
}

# Check if script is run with sudo
if [ "$EUID" -ne 0 ]; then
echo "Please run as root or with sudo."
Expand Down Expand Up @@ -53,6 +63,12 @@ fi
run_command "mkdir -p ${INSTALL_DIR}"
run_command "mkdir -p ${DATA_DIR}"

# Backup files if they already exist
backup_if_exists "${INSTALL_DIR}/auth.yaml"
backup_if_exists "${INSTALL_DIR}/config.yaml"
backup_if_exists "${INSTALL_DIR}/.p4config"
backup_if_exists "${BIN_DIR}/datapushgateway"

# Copy files to appropriate locations
run_command "install -m 0755 datapushgateway ${BIN_DIR}/datapushgateway"
run_command "install -m 0644 auth.yaml ${INSTALL_DIR}/auth.yaml"
Expand Down Expand Up @@ -121,6 +137,7 @@ echo "Installation completed."
if $DRY_RUN; then
echo "Dry run completed. No changes were made."
fi

# If not in dry run, echo the contents of the configuration files
if ! $DRY_RUN; then
echo "Contents of ${INSTALL_DIR}/auth.yaml:"
Expand All @@ -134,4 +151,4 @@ if ! $DRY_RUN; then
echo "Contents of ${INSTALL_DIR}/.p4config:"
cat "${INSTALL_DIR}/.p4config"
echo "------------PLEASE EDIT--------------"
fi
fi

0 comments on commit 22d2565

Please sign in to comment.