-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
66 lines (53 loc) · 1.61 KB
/
setup.sh
File metadata and controls
66 lines (53 loc) · 1.61 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
65
66
#!/bin/bash
################
# Update .env
# Path to the .env file
ENV_FILE=".env"
# Set default values if arguments are not provided
DEFAULT_SHARES=3
DEFAULT_THRESHOLD=2
MIN_PARTICIPANTS=3
# Check if SHARES and THRESHOLD arguments are provided
if [ -z "$1" ]; then
echo "SHARES not provided, using default: $DEFAULT_SHARES"
NEW_SHARES=$DEFAULT_SHARES
else
NEW_SHARES=$1
fi
if [ -z "$2" ]; then
echo "THRESHOLD not provided, using default: $DEFAULT_THRESHOLD"
NEW_THRESHOLD=$DEFAULT_THRESHOLD
else
NEW_THRESHOLD=$2
fi
# Validate that SHARES is at least 5
if [ "$NEW_SHARES" -lt "$MIN_PARTICIPANTS" ]; then
echo "Error: SHARES must be at least $MIN_PARTICIPANTS."
exit 1
fi
# Validate that THRESHOLD is less than or equal to SHARES
if [ "$NEW_THRESHOLD" -gt "$NEW_SHARES" ]; then
echo "Error: THRESHOLD must be less than or equal to SHARES."
exit 1
fi
# Update or append SHARES and THRESHOLD in .env file
if grep -q "^SHARES=" "$ENV_FILE"; then
sed -i '' "s/^SHARES=.*/SHARES=$NEW_SHARES/" "$ENV_FILE" # Added '' after -i for macOS compatibility
else
echo "SHARES=$NEW_SHARES" >> "$ENV_FILE"
fi
if grep -q "^THRESHOLD=" "$ENV_FILE"; then
sed -i '' "s/^THRESHOLD=.*/THRESHOLD=$NEW_THRESHOLD/" "$ENV_FILE" # Added '' after -i for macOS compatibility
else
echo "THRESHOLD=$NEW_THRESHOLD" >> "$ENV_FILE"
fi
echo "Updated .env with SHARES=$NEW_SHARES and THRESHOLD=$NEW_THRESHOLD."
################
# Clear data folder
DIR="data"
if [ -d "$DIR" ]; then
rm -rf "$DIR"
echo "Directory '$DIR' and its contents have been deleted."
else
echo "Directory '$DIR' does not exist."
fi