dev-env/script/update_profile
2024-12-21 01:45:09 +01:00

35 lines
972 B
Bash
Executable File

#!/bin/bash
ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )
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
echo "[DEV-ENV]: Template file '$TEMPLATE_FILE' does not exist. Skip updating .profile."
exit 1
fi
TEMPLATE_CONTENT=$(<"$TEMPLATE_FILE")
echo "[DEV-ENV]: Update $PROFILE_FILE"
# Check if start marker already exists in profile file
if grep -q "$START_MARKER" "$PROFILE_FILE"; then
echo "[DEV-ENV]: Section already exists. Update contents..."
# Remove contents between start and end marker
sed -i "/$START_MARKER/,/$END_MARKER/d" "$PROFILE_FILE"
else
echo "[DEV-ENV]: Section does not exists. Adding contents..."
fi
# Add contents
echo -e "\n$START_MARKER\n$TEMPLATE_CONTENT\n$END_MARKER" >> "$PROFILE_FILE"
echo "[DEV-ENV]: Successfully updated $PROFILE_FILE"