Initial commit
This commit is contained in:
8
bash-scripts/copy_env.sh
Normal file
8
bash-scripts/copy_env.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if .env does not exist and .example.env exists
|
||||
if [ ! -f ".env" ] && [ -f ".example.env" ]; then
|
||||
# Copy .example.env to .env
|
||||
cp .example.env .env
|
||||
echo ".example.env has been copied to .env"
|
||||
fi
|
||||
91
bash-scripts/set_global_env.sh
Normal file
91
bash-scripts/set_global_env.sh
Normal file
@@ -0,0 +1,91 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Default values
|
||||
CLI_CEB_DEV=false
|
||||
CLI_CEB_FIREFOX=false
|
||||
|
||||
validate_is_boolean() {
|
||||
if [[ "$1" != "true" && "$1" != "false" ]]; then
|
||||
echo "Invalid value for <$2>. Please use 'true' or 'false'."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Validate if a key starts with CLI_CEB_ or CEB_
|
||||
validate_key() {
|
||||
local key="$1"
|
||||
local is_editable_section="${2:-false}"
|
||||
|
||||
if [[ -n "$key" && ! "$key" =~ ^# ]]; then
|
||||
if [[ "$is_editable_section" == true && ! "$key" =~ ^CEB_ ]]; then
|
||||
echo "Invalid key: <$key>. All keys in the editable section must start with 'CEB_'."
|
||||
exit 1
|
||||
elif [[ "$is_editable_section" == false && ! "$key" =~ ^CLI_CEB_ ]]; then
|
||||
echo "Invalid key: <$key>. All CLI keys must start with 'CLI_CEB_'."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
parse_arguments() {
|
||||
for arg in "$@"
|
||||
do
|
||||
key="${arg%%=*}"
|
||||
value="${arg#*=}"
|
||||
|
||||
validate_key "$key"
|
||||
|
||||
case $key in
|
||||
CLI_CEB_DEV)
|
||||
CLI_CEB_DEV="$value"
|
||||
validate_is_boolean "$CLI_CEB_DEV" "CLI_CEB_DEV"
|
||||
;;
|
||||
CLI_CEB_FIREFOX)
|
||||
CLI_CEB_FIREFOX="$value"
|
||||
validate_is_boolean "$CLI_CEB_FIREFOX" "CLI_CEB_FIREFOX"
|
||||
;;
|
||||
*)
|
||||
cli_values+=("$key=$value")
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Validate keys in .env file
|
||||
validate_env_keys() {
|
||||
editable_section_starts=false
|
||||
|
||||
while IFS= read -r line; do
|
||||
key="${line%%=*}"
|
||||
if [[ "$key" =~ ^CLI_CEB_ ]]; then
|
||||
editable_section_starts=true
|
||||
elif $editable_section_starts; then
|
||||
validate_key "$key" true
|
||||
fi
|
||||
done < .env
|
||||
}
|
||||
|
||||
create_new_file() {
|
||||
temp_file=$(mktemp)
|
||||
|
||||
{
|
||||
echo "# THOSE VALUES ARE EDITABLE ONLY VIA CLI"
|
||||
echo "CLI_CEB_DEV=$CLI_CEB_DEV"
|
||||
echo "CLI_CEB_FIREFOX=$CLI_CEB_FIREFOX"
|
||||
for value in "${cli_values[@]}"; do
|
||||
echo "$value"
|
||||
done
|
||||
echo ""
|
||||
echo "# THOSE VALUES ARE EDITABLE"
|
||||
|
||||
# Copy existing env values, without CLI section
|
||||
grep -E '^CEB_' .env
|
||||
} > "$temp_file"
|
||||
|
||||
mv "$temp_file" .env
|
||||
}
|
||||
|
||||
# Main script execution
|
||||
parse_arguments "$@"
|
||||
validate_env_keys
|
||||
create_new_file
|
||||
17
bash-scripts/update_version.sh
Normal file
17
bash-scripts/update_version.sh
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
# Usage: ./update_version.sh <new_version>
|
||||
# FORMAT IS <0.0.0>
|
||||
|
||||
if [[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||
find . -name 'package.json' -not -path '*/node_modules/*' -exec bash -c '
|
||||
# Parse the version from package.json
|
||||
current_version=$(grep -o "\"version\": \"[^\"]*" "$0" | cut -d"\"" -f4)
|
||||
|
||||
# Update the version
|
||||
perl -i -pe"s/$current_version/'$1'/" "$0"
|
||||
' {} \;
|
||||
|
||||
echo "Updated versions to $1";
|
||||
else
|
||||
echo "Version format <$1> isn't correct, proper format is <0.0.0>";
|
||||
fi
|
||||
Reference in New Issue
Block a user