Skip to content

Commit

Permalink
Replace sr3_remove with sr3d remove, change sr3d for #2 and #6
Browse files Browse the repository at this point in the history
  • Loading branch information
reidsunderland committed Oct 18, 2023
1 parent a822a28 commit 858f8e5
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 39 deletions.
64 changes: 64 additions & 0 deletions bin/sr3_action_remove
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

#
# sr3 remove ... will remove the configs on the nodes.
# The git repo needs to be updated to match.
#

source sr3_utils

MAIN_BRANCH="main"

# sets git_tld and pump_name
sr3_get_git_path_pump_name

pump_path="${git_tld}/${pump_name}/"

# Get the absolute paths to the files to be removed
files_to_remove=""
for argu in "$@"; do
if [[ "$argu" == "remove" ]] ; then
continue
fi
files_to_remove="${files_to_remove} ${pump_path}${argu}.conf"
done

if [ -z "${files_to_remove}" ]; then
echo '[ERROR] no files to remove'
exit 2
fi

# Files must exist
for file in ${files_to_remove}; do
if [ ! -f "${file}" ]; then
echo "[ERROR] File does not exist: ${file}"
exit 3
fi
done

# Directory must be controlled by Git
if ! git status > /dev/null; then
echo '[ERROR] this directory is not version controlled with Git'
exit 4
fi

# Update the repository
if ! git pull origin "${MAIN_BRANCH}"; then
echo "[ERROR] Problem updating local repository. Please resolve manually and retry."
exit 5
fi

# Remove the files and commit the change
for file in ${files_to_remove}; do
cp -p "${file}" "${file}.off"
done
git rm ${files_to_remove}
git commit

if ! git push origin; then
echo "[ERROR] Problems were encountered during repository push."
exit 6
fi

# Nodes get updated from the remote Git repo
sr3_pull
79 changes: 41 additions & 38 deletions bin/sr3_remove
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,44 @@ MAIN_BRANCH="main"

YELLOW='\033[1;33m'
NORMAL='\033[0m'
echo -e "${YELLOW}[WARNING]${NORMAL} sr3_remove is deprecated. Use Git and sr3_pull instead."

if [ $# != 1 ]; then
echo '[ERROR] no file to remove'
echo 'Usage: sr3_remove filename'
exit 2
fi

# File must exist
if [ ! -f "${PWD}/$1" ]; then
echo "[ERROR] File does not exist: ${PWD}/$1"
exit 3
fi

# Directory must be controlled by Git
if ! git status > /dev/null; then
echo '[ERROR] this directory is not version controlled with Git'
exit 4
fi

# Update the repository
if ! git pull origin "${MAIN_BRANCH}"; then
echo "[ERROR] Problem updating local repository. Please resolve manually and retry."
exit 5
fi

# Remove the file and commit the change
cp -p "$1" "${1}.off"
git rm "$1"
git commit "$1"

if ! git push origin; then
echo "[ERROR] Problems were encountered during repository push."
exit 6
fi

# Nodes get updated from the remote Git repo
sr3_pull
#echo -e "${YELLOW}[WARNING]${NORMAL} sr3_remove is deprecated. Use Git and sr3_pull instead."

echo -e "${YELLOW}[WARNING]${NORMAL} sr3_remove is deprecated. Use sr3d remove component/config instead."
exit 0

# if [ $# != 1 ]; then
# echo '[ERROR] no file to remove'
# echo 'Usage: sr3_remove filename'
# exit 2
# fi

# # File must exist
# if [ ! -f "${PWD}/$1" ]; then
# echo "[ERROR] File does not exist: ${PWD}/$1"
# exit 3
# fi

# # Directory must be controlled by Git
# if ! git status > /dev/null; then
# echo '[ERROR] this directory is not version controlled with Git'
# exit 4
# fi

# # Update the repository
# if ! git pull origin "${MAIN_BRANCH}"; then
# echo "[ERROR] Problem updating local repository. Please resolve manually and retry."
# exit 5
# fi

# # Remove the file and commit the change
# cp -p "$1" "${1}.off"
# git rm "$1"
# git commit "$1"

# if ! git push origin; then
# echo "[ERROR] Problems were encountered during repository push."
# exit 6
# fi

# # Nodes get updated from the remote Git repo
# sr3_pull
17 changes: 16 additions & 1 deletion bin/sr3d
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
#!/bin/bash
sr3r "sr3 $*"
action="$1"

# Special cases for certain actions BEFORE running on nodes
if ([[ "$action" == "add" ]] || [[ "$action" == "convert" ]] || [[ "$action" == "foreground" ]] ||
[[ "$action" == "convert" ]] || [[ "$action" == "run" ]] ); then
echo "Action ${action} is not supported with sr3d."
echo "https://github.com/MetPX/sr3_tools/issues/2"
fi

sr3r "sr3 $*"

# Special cases for certain actions AFTER running on nodes

if [[ "$action" == "remove" ]] ; then
sr3_action_remove $*
fi

0 comments on commit 858f8e5

Please sign in to comment.