-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathclean
More file actions
executable file
·64 lines (56 loc) · 1.56 KB
/
clean
File metadata and controls
executable file
·64 lines (56 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
#
# Usage:
#
# $> source clean [--force]
#
#=========================================================================================
# Environment
#
export __script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [[ ! " $@ " =~ " --force " ]]; then
read -p "This is a DESTRUCTIVE operation. Type YES to continue: " choice
case "$choice" in
[Yy][Ee][Ss])
;;
*)
echo "Aborting"
return
;;
esac
fi
#
#=========================================================================================
# Execution
#
#
# 1. Terminate all Docker services and remove artifacts
#
if [ "${ZIMAGI_APP_NAME}" ]; then
docker ps --filter name="${ZIMAGI_APP_NAME}.worker-" --filter status=running -aq | xargs -r docker rm -f
docker ps --filter name="${ZIMAGI_APP_NAME}.agent-" --filter status=running -aq | xargs -r docker rm -f
fi
if [ "$COMPOSE_FILE" ]; then
docker compose down --remove-orphans --volumes
fi
#
# 2. Remove dynamically generated environment files (exclude generated)
#
rm -f "${__script_dir}/.env"
#
# 3. Clean up terminal environment
#
export PATH="${PATH//"${__script_dir}:"/}"
while IFS= read -r variable; do
unset "${variable}"
done <<< "$(env | grep -o "__zimagi_[_a-zA-Z0-9]*")"
while IFS= read -r variable; do
unset "${variable}"
done <<< "$(env | grep -o "ZIMAGI_[_A-Z0-9]*")"
while IFS= read -r variable; do
unset "${variable}"
done <<< "$(env | grep -o "DEFAULT_ZIMAGI_[_A-Z0-9]*")"
while IFS= read -r variable; do
unset "${variable}"
done <<< "$(env | grep -o "COMPOSE_[_A-Z0-9]*")"
unset __script_dir