dev-env/script/update_profile
2025-01-04 04:33:07 +01:00

34 lines
1002 B
Bash
Executable File

#!/bin/bash
ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )
source $ENV_DIR/bin/denv_msg
PROFILE_FILE="$HOME/.profile"
TEMPLATE_FILE="$ENV_DIR/.profile"
START_MARKER="#DEV ENV SETUP START"
END_MARKER="#DEV ENV SETUP END"
# Check if template file exists
if [ ! -f "$TEMPLATE_FILE" ]; then
denv_error_msg "[dev-env]: Template file '$TEMPLATE_FILE' does not exist. Skip updating .profile."
exit 1
fi
TEMPLATE_CONTENT=$(<"$TEMPLATE_FILE")
# Check if start marker already exists in profile file
if grep -q "$START_MARKER" "$PROFILE_FILE"; then
denv_echo_msg "[dev-env]: Section already exists. Update contents..."
# Remove contents between start and end marker
sed -i "/$START_MARKER/,/$END_MARKER/d" "$PROFILE_FILE"
else
denv_echo_msg "[dev-env]: Section does not exists. Adding contents..."
fi
ENV_DIR_STRING="# path\nDEV_ENV_PATH=$ENV_DIR\n"
# Add contents
echo -e "\n$START_MARKER\n$ENV_DIR_STRING\n$TEMPLATE_CONTENT\n$END_MARKER" >> "$PROFILE_FILE"