v3.2.0
===================================================================== --- Changes ------------------------------ - split up environment files per scwrypts group - updated i3/launch-or-show to provide some new options --- Bug Fixes ---------------------------- - utils/io commands like 'STATUS' no longer throw errors '%' characters - fixed ERROR_CHECK function calls to CHECK_ERRORS
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
#!/bin/zsh
|
||||
#!/bin/zsh
|
||||
DEPENDENCIES+=()
|
||||
REQUIRED_ENV+=()
|
||||
|
||||
@ -16,18 +16,23 @@ STATUS "selected '$TEMPLATE_ENV_NAME'"
|
||||
PROMPT 'enter new environment name'
|
||||
ENV_NAME=$(echo '' | FZF_HEAD 'new environment')
|
||||
[ ! $ENV_NAME ] && ABORT
|
||||
SCWRYPTS__GET_ENV_NAMES | grep -q $ENV_NAME && FAIL 1 "'$ENV_NAME' already exists"
|
||||
|
||||
TEMPLATE_ENV_FILE=$(SCWRYPTS__GET_ENV_FILE $TEMPLATE_ENV_NAME 2>/dev/null)
|
||||
ENV_FILE=$(SCWRYPTS__GET_ENV_FILE $ENV_NAME)
|
||||
for GROUP in ${SCWRYPTS_GROUPS[@]}
|
||||
do
|
||||
TEMPLATE_ENV_FILE=$(SCWRYPTS__GET_ENV_FILE $TEMPLATE_ENV_NAME $GROUP 2>/dev/null)
|
||||
ENV_FILE=$(SCWRYPTS__GET_ENV_FILE $ENV_NAME $GROUP 2>/dev/null)
|
||||
|
||||
[ -f "$ENV_FILE" ] && FAIL 2 "'$ENV_NAME' already exists"
|
||||
STATUS "creating environment '$ENV_NAME'"
|
||||
cat "$TEMPLATE_ENV_FILE" \
|
||||
| sed 's/ # from.*//' \
|
||||
> "$ENV_FILE" \
|
||||
&& SUCCESS "created '$ENV_FILE'" \
|
||||
|| FAIL 2 "something went wrong creating '$ENV_FILE'"
|
||||
done
|
||||
|
||||
STATUS "creating environment '$ENV_NAME'"
|
||||
cat "$TEMPLATE_ENV_FILE" \
|
||||
| sed 's/ from.*//' \
|
||||
> "$ENV_FILE" \
|
||||
&& SCWRYPTS__RUN --name scwrypts/environment/synchronize --group scwrypts --type zsh -- --no-prompt \
|
||||
&& SUCCESS "created '$ENV_NAME'" \
|
||||
|| FAIL 3 "something went wrong creating '$ENV_NAME'"
|
||||
|
||||
SUCCESS "finished copy environment '$TEMPLATE_ENV_NAME > $ENV_NAME'"
|
||||
STATUS "synchronizing environments"
|
||||
SCWRYPTS__RUN --name scwrypts/environment/synchronize --group scwrypts --type zsh -- --no-prompt \
|
||||
&& SUCCESS "finished copy environment '$TEMPLATE_ENV_NAME > $ENV_NAME'" \
|
||||
|| FAIL 3 'error during synchronization of new environment (see above)' \
|
||||
;
|
||||
|
@ -11,18 +11,26 @@ PROMPT 'choose an environment to delete'
|
||||
ENV_NAME=$(SCWRYPTS__SELECT_ENV)
|
||||
[ ! $ENV_NAME ] && ABORT
|
||||
|
||||
ENV_FILE=$(SCWRYPTS__GET_ENV_FILE $ENV_NAME)
|
||||
ENV_FILES=($(SCWRYPTS__GET_ENV_FILES $ENV_NAME))
|
||||
|
||||
STATUS "preparing to remove '$ENV_NAME'"
|
||||
|
||||
WARNING "
|
||||
the '$ENV_NAME' environment will be removed
|
||||
configured options and stored credentials will be lost forever
|
||||
the '$ENV_NAME' environment will be removed configured options
|
||||
and stored credentials will be lost forever:
|
||||
|
||||
$(echo $ENV_FILES | sed 's| /|\n - /|g; s/^/ - /')
|
||||
"
|
||||
|
||||
yN 'continue?' || ABORT
|
||||
|
||||
STATUS "removing environment"
|
||||
rm "$ENV_FILE" \
|
||||
&& SUCCESS "removed '$ENV_NAME'" \
|
||||
|| FAIL 3 "unable to remove '$ENV_FILE'; is it protected?"
|
||||
for ENV_FILE in ${ENV_FILES[@]}
|
||||
do
|
||||
rm "$ENV_FILE" \
|
||||
&& SUCCESS "removed '$ENV_FILE'" \
|
||||
|| ERROR "unable to remove '$ENV_FILE'; is it protected?" \
|
||||
;
|
||||
done
|
||||
|
||||
CHECK_ERRORS -n || FAIL 2 "some errors ocurred when cleaning up $ENV_NAME"
|
||||
|
@ -16,16 +16,26 @@ CHECK_ENVIRONMENT
|
||||
}
|
||||
[ ! $ENV_NAME ] && ABORT
|
||||
|
||||
ENV_FILE=$(SCWRYPTS__GET_ENV_FILE $ENV_NAME 2>/dev/null)
|
||||
[ ! -f "$ENV_FILE" ] && {
|
||||
STATUS "Creating '$ENV_NAME'..." \
|
||||
&& touch "$ENV_FILE" \
|
||||
&& SCWRYPTS__RUN --name scwrypts/environment/synchronize --group scwrypts --type zsh -- --no-prompt \
|
||||
&& SUCCESS "created '$ENV_NAME'" \
|
||||
|| { ERROR "failed to create '$ENV_FILE'"; exit 1; }
|
||||
}
|
||||
ENV_FILES=($(SCWRYPTS__GET_ENV_FILES $ENV_NAME 2>/dev/null))
|
||||
for ENV_FILE in ${ENV_FILES[@]}
|
||||
do
|
||||
[ ! -f "$ENV_FILE" ] && {
|
||||
STATUS "Creating '$ENV_FILE'..." \
|
||||
&& touch "$ENV_FILE" \
|
||||
&& ((CREATED+=1)) \
|
||||
&& SUCCESS "created '$ENV_NAME'" \
|
||||
|| { ERROR "failed to create '$ENV_FILE'"; exit 1; }
|
||||
}
|
||||
|
||||
EDIT $ENV_FILE
|
||||
[ $CREATED ] && [[ $CREATED -gt 0 ]] && {
|
||||
STATUS "detected new environment files; performing sync" \
|
||||
&& SCWRYPTS__RUN --name scwrypts/environment/synchronize --group scwrypts --type zsh -- --no-prompt \
|
||||
|| FAIL 1 "failure during sync for '$ENV_NAME'" \
|
||||
}
|
||||
;
|
||||
done
|
||||
|
||||
EDIT $ENV_FILES
|
||||
|
||||
SCWRYPTS__RUN --name scwrypts/environment/synchronize --group scwrypts --type zsh -- --no-prompt \
|
||||
|| FAIL 4 'failed to run environment sync' \
|
||||
|
@ -1,8 +0,0 @@
|
||||
#!/bin/zsh
|
||||
DEPENDENCIES+=()
|
||||
REQUIRED_ENV+=()
|
||||
|
||||
CHECK_ENVIRONMENT
|
||||
#####################################################################
|
||||
|
||||
__CHECK_REQUIRED_ENV $@
|
@ -49,39 +49,47 @@ SYNCHRONIZE() {
|
||||
local ENVIRONMENTS ENVIRONMENT_FILES
|
||||
local FILE NAME ENVIRONMENT_FILE
|
||||
|
||||
ENVIRONMENTS=($(SCWRYPTS__GET_ENV_NAMES | sort -r))
|
||||
ENVIRONMENT_FILES=($(
|
||||
GROUP_PIDS=()
|
||||
for GROUP in ${SCWRYPTS_GROUPS}
|
||||
do
|
||||
{
|
||||
ENVIRONMENTS=($(SCWRYPTS__GET_ENV_NAMES | sort -r))
|
||||
ENVIRONMENT_FILES=($(
|
||||
for NAME in ${ENVIRONMENTS[@]}
|
||||
do
|
||||
SCWRYPTS__GET_ENV_FILE $NAME $GROUP
|
||||
done
|
||||
))
|
||||
|
||||
STATUS 'generating working environment files...'
|
||||
for FILE in ${ENVIRONMENT_FILES[@]}
|
||||
do
|
||||
GENERATE_TEMP_ENVIRONMENT_FILE "$FILE"
|
||||
done
|
||||
|
||||
STATUS 'cascading environment values to children...'
|
||||
for NAME in ${ENVIRONMENTS[@]}
|
||||
do
|
||||
SCWRYPTS__GET_ENV_FILE $NAME
|
||||
CASCADE_ENVIRONMENT $NAME
|
||||
done
|
||||
))
|
||||
|
||||
STATUS 'generating working environment files...'
|
||||
for FILE in ${ENVIRONMENT_FILES[@]}
|
||||
do
|
||||
GENERATE_TEMP_ENVIRONMENT_FILE "$FILE"
|
||||
STATUS 'cleaning up working space...'
|
||||
for FILE in ${ENVIRONMENT_FILES[@]}
|
||||
do
|
||||
CLEANUP_ENVIRONMENT_FILE "$FILE"
|
||||
done
|
||||
SUCCESS 'finished sync!'
|
||||
} &
|
||||
GROUP_PIDS+=$!
|
||||
done
|
||||
|
||||
STATUS 'cascading environment values to children...'
|
||||
for NAME in ${ENVIRONMENTS[@]}
|
||||
do
|
||||
CASCADE_ENVIRONMENT $NAME
|
||||
done
|
||||
|
||||
STATUS 'cleaning up working space...'
|
||||
for FILE in ${ENVIRONMENT_FILES[@]}
|
||||
do
|
||||
CLEANUP_ENVIRONMENT_FILE "$FILE"
|
||||
done
|
||||
SUCCESS 'finished sync!'
|
||||
for P in ${GROUP_PIDS[@]}; do wait $P; done
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
|
||||
CASCADE_ENVIRONMENT() {
|
||||
local PARENT_NAME="$1"
|
||||
local PARENT_FILE="$(SCWRYPTS__GET_ENV_FILE $PARENT_NAME).temp"
|
||||
local PARENT_FILE="$(SCWRYPTS__GET_ENV_FILE $PARENT_NAME $GROUP).temp"
|
||||
|
||||
local CHILD_NAMES=($(echo $ENVIRONMENTS | sed 's/ \+/\n/g' |grep "^$PARENT_NAME\\."))
|
||||
[[ ${#CHILD_NAMES[@]} -eq 0 ]] && return 0
|
||||
@ -93,7 +101,7 @@ CASCADE_ENVIRONMENT() {
|
||||
for CHILD_NAME in ${CHILD_NAMES[@]}
|
||||
do
|
||||
STATUS "propagating environment '$PARENT_NAME' to child '$CHILD_NAME'"
|
||||
CHILD_FILE="$(SCWRYPTS__GET_ENV_FILE $CHILD_NAME).temp"
|
||||
CHILD_FILE="$(SCWRYPTS__GET_ENV_FILE $CHILD_NAME $GROUP).temp"
|
||||
CONTENT=$(cat "$CHILD_FILE")
|
||||
echo "$PARENT_VARIABLES" | ADD_LINES
|
||||
echo "$CONTENT" > "$CHILD_FILE"
|
||||
|
Reference in New Issue
Block a user