Skip to content

Commit cb0eeba

Browse files
Second round of fixing
* fix cleaning work directory script
1 parent 2c88de9 commit cb0eeba

2 files changed

Lines changed: 63 additions & 50 deletions

File tree

scripts/auto_upgrader/auto_upgrader_upgrade.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ setup_process() {
6060
echo "⚙️ Setting up for 'process' mode..."
6161

6262
# Upgrade the auto upgrader as process
63-
./subvortex/auto_upgrader/deployment/process/auto_upgrader_process_upgrade.sh --tag $TAG --branch $BRANCH
63+
./subvortex/auto_upgrader/deployment/process/auto_upgrader_process_upgrade.sh --tag "$TAG" --branch "$BRANCH"
6464

6565
# Add any other logic specific to process mode here
6666
echo "✅ Process started."
@@ -71,7 +71,7 @@ setup_container() {
7171
echo "🐳 Setting up for 'container' mode..."
7272

7373
# Start the auto upgrader as service
74-
./subvortex/auto_upgrader/deployment/container/auto_upgrader_container_upgrade.sh --tag $TAG --branch $BRANCH
74+
./subvortex/auto_upgrader/deployment/container/auto_upgrader_container_upgrade.sh --tag "$TAG" --branch "$BRANCH"
7575

7676
# Add any other container-specific logic here
7777
echo "✅ Container started."
@@ -82,7 +82,7 @@ setup_service() {
8282
echo "🧩 Setting up for 'service' mode..."
8383

8484
# Start the auto upgrader as service
85-
./subvortex/auto_upgrader/deployment/service/auto_upgrader_service_upgrade.sh --tag $TAG --branch $BRANCH
85+
./subvortex/auto_upgrader/deployment/service/auto_upgrader_service_upgrade.sh --tag "$TAG" --branch "$BRANCH"
8686

8787
# Add logic for systemd, service checks, etc. if needed
8888
echo "✅ Service started."

scripts/clean_workspace.sh

Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
set -e
44

5-
SHOW_HELP=false
65
REMOVE_LATEST=false
76

8-
# --- Usage function ---
97
usage() {
108
cat <<EOF
11-
Usage: $(basename "$0") [OPTIONS] <directory>
9+
Usage: $(basename "$0") [OPTIONS]
1210
13-
Clean all contents of a directory except the latest versioned "subvortex-X.Y.Z-[alpha|rc].W" subdirectory.
11+
Clean all contents under /var/tmp/subvortex,
12+
preserving only the latest versioned directory and all non-versioned ones.
13+
With --remove, remove everything.
1414
1515
Options:
16-
-r, --remove Remove the latest version directory as well
16+
-r, --remove Remove all versioned and non-versioned directories
1717
-h, --help Show this help message and exit
1818
1919
Examples:
@@ -22,8 +22,20 @@ Examples:
2222
EOF
2323
}
2424

25-
# --- Parse arguments ---
26-
ARGS=()
25+
# Determine compatible version sort command
26+
version_sort() {
27+
if command -v sort >/dev/null && sort -V </dev/null &>/dev/null; then
28+
sort -V
29+
elif command -v gsort >/dev/null; then
30+
gsort -V
31+
else
32+
echo "❌ Error: version sort (sort -V or gsort -V) not supported on this system." >&2
33+
echo "👉 On macOS, run: brew install coreutils" >&2
34+
exit 1
35+
fi
36+
}
37+
38+
# Parse arguments
2739
while [[ $# -gt 0 ]]; do
2840
case "$1" in
2941
-r|--remove)
@@ -40,64 +52,65 @@ while [[ $# -gt 0 ]]; do
4052
exit 1
4153
;;
4254
*)
43-
ARGS+=("$1")
44-
shift
55+
echo "❌ Unexpected argument: $1"
56+
usage
57+
exit 1
4558
;;
4659
esac
4760
done
4861

49-
# Restore positional parameters
50-
set -- "${POSITIONAL[@]}"
51-
52-
# Show help if requested
53-
if [ "$SHOW_HELP" = true ]; then
54-
exit 0
55-
fi
56-
57-
# Check directory argument
58-
TARGET_DIR=/var/tmp/subvortex
62+
TARGET_BASE="/var/tmp/subvortex"
5963

60-
if [ -z "$TARGET_DIR" ]; then
61-
echo "❌ Error: No directory provided."
64+
if [ ! -d "$TARGET_BASE" ]; then
65+
echo "❌ Error: Directory '$TARGET_BASE' does not exist."
6266
exit 1
6367
fi
6468

65-
if [ ! -d "$TARGET_DIR" ]; then
66-
echo "❌ Error: Directory '$TARGET_DIR' does not exist."
67-
exit 1
68-
fi
69+
cd "$TARGET_BASE"
70+
all_dirs=($(find . -maxdepth 1 -mindepth 1 -type d -exec basename {} \;))
71+
72+
versioned_dirs=()
73+
non_versioned_dirs=()
6974

70-
# --- Find and preserve the latest subvortex version ---
71-
cd "$TARGET_DIR"
72-
version_dirs=($(find . -maxdepth 1 -type d -name "subvortex-*" -exec basename {} \; | grep -E '^subvortex-[0-9]+\.[0-9]+\.[0-9]+([a-z]+\d+)?$'))
75+
# Classify directories
76+
for dir in "${all_dirs[@]}"; do
77+
if [[ "$dir" =~ ^subvortex-[0-9]+\.[0-9]+\.[0-9]+([^/]+)?$ ]]; then
78+
versioned_dirs+=("$dir")
79+
else
80+
non_versioned_dirs+=("$dir")
81+
fi
82+
done
7383

74-
if [ ${#version_dirs[@]} -eq 0 ]; then
75-
echo "⚠️ No matching subvortex version directories found."
76-
exit 0
84+
# Identify latest versioned directory
85+
latest_version=""
86+
if [ ${#versioned_dirs[@]} -gt 0 ]; then
87+
latest_version=$(printf "%s\n" "${versioned_dirs[@]}" | version_sort | tail -n 1)
7788
fi
7889

79-
latest_version=$(printf "%s\n" "${version_dirs[@]}" | sort -V | tail -n 1)
90+
echo "🧹 Cleaning up: $TARGET_BASE"
8091

81-
if [ "$REMOVE_LATEST" = false ]; then
82-
echo "🛡️ Preserving latest version: $latest_version"
83-
else
84-
echo "🧨 '--remove' provided — deleting everything, including: $latest_version"
85-
fi
92+
for dir in "${all_dirs[@]}"; do
93+
keep=false
8694

87-
# --- Remove content ---
88-
for entry in "$TARGET_DIR"/* "$TARGET_DIR"/.*; do
89-
base=$(basename "$entry")
95+
if [ "$REMOVE_LATEST" = false ]; then
96+
for nvd in "${non_versioned_dirs[@]}"; do
97+
if [ "$dir" == "$nvd" ]; then
98+
keep=true
99+
break
100+
fi
101+
done
90102

91-
if [ "$base" == "." ] || [ "$base" == ".." ]; then
92-
continue
103+
if [ "$dir" == "$latest_version" ]; then
104+
keep=true
105+
fi
93106
fi
94107

95-
if [ "$REMOVE_LATEST" = false ] && [ "$base" == "$latest_version" ]; then
96-
continue
108+
if [ "$keep" = true ]; then
109+
echo "🛡️ Preserving: $dir"
110+
else
111+
echo "🔥 Removing: $dir"
112+
rm -rf "$dir"
97113
fi
98-
99-
echo "🧹 Removing: $entry"
100-
rm -rf "$entry"
101114
done
102115

103116
echo "✅ Cleanup complete."

0 commit comments

Comments
 (0)