-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_secrects.sh
79 lines (79 loc) · 2.57 KB
/
create_secrects.sh
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
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
SECRETS_DIR_NAME=.secrets
SECRETS_DIR="$PWD/$SECRETS_DIR_NAME"
SECRETS_FILE_NAME=secrets.properties
#
if [ -d "$SECRETS_DIR" ];
then
echo "➡️ $SECRETS_DIR_NAME directory exists."
cd "$SECRETS_DIR"
if [ -f "$PWD/$SECRETS_FILE_NAME" ]
then
echo "➡️ $SECRETS_FILE_NAME file exists."
# Check if GitHub token exists in secrets file
GITHUB_TOKEN=$(grep -iR "^GITHUB_TOKEN" "$SECRETS_FILE_NAME" | awk -F "=" '{print $2}')
#
if [ -z "$GITHUB_TOKEN" ]
then
echo "➡️ Invalid or empty GITHUB_TOKEN ⚠️"
# Open user input
read -p "Enter GitHub Token: " GITHUB_TOKEN
echo "➡️ Writing GitHub Token to $SECRETS_FILE_NAME file..."
if echo -e "GITHUB_TOKEN=$GITHUB_TOKEN" >> $SECRETS_FILE_NAME; then
echo "✅ GitHub token saved successfully."
read -n1 -s -r -p $'➡️ Press any key to exit \n' key
echo "Thank you."
exit 0
else
echo -e "\033[0;31m🚫 Failed to save GitHub token!"
fi
else
echo "➡️ GitHub token exists."
exit 0
fi
else
echo "➡️ $SECRETS_FILE_NAME file does not exist ⚠️"
echo "➡️ Creating $SECRETS_FILE_NAME file..."
if touch $SECRETS_FILE_NAME; then
echo "✅ $SECRETS_FILE_NAME created successfully."
# Open user input
read -p "Enter GitHub Token: " GITHUB_TOKEN
echo "➡️ Writing GitHub Token to $SECRETS_FILE_NAME file..."
if echo -e "GITHUB_TOKEN=$GITHUB_TOKEN" >> $SECRETS_FILE_NAME; then
echo "✅ GitHub token saved successfully."
read -n1 -s -r -p $'➡️ Press any key to exit \n' key
echo "Thank you."
exit 0
else
echo -e "\033[0;31m🚫 Failed to save GitHub token!"
fi
else
echo "🚫 Failed ot create $SECRETS_FILE_NAME!"
fi
fi
else
echo "➡️ $SECRETS_DIR directory does not exist ⚠️"
echo "➡️ Creating $SECRETS_DIR directory..."
if mkdir $SECRETS_DIR_NAME; then
echo "✅ $SECRETS_DIR_NAME directory created successfully."
echo "➡️ Creating $SECRETS_FILE_NAME file..."
if touch $SECRETS_FILE_NAME; then
echo "✅ $SECRETS_FILE_NAME created successfully."
# Open user input
read -p "Enter GitHub Token: " GITHUB_TOKEN
echo "➡️ Writing GitHub Token to $SECRETS_FILE_NAME file..."
if echo -e "GITHUB_TOKEN=$GITHUB_TOKEN" >> $SECRETS_FILE_NAME; then
echo "✅ GitHub token saved successfully."
read -n1 -s -r -p $'➡️ Press any key to exit \n' key
echo "Thank you."
exit 0
else
echo -e "\033[0;31m🚫 Failed to save GitHub token!"
fi
else
echo "🚫 Failed ot create $SECRETS_FILE_NAME!"
fi
else
echo "🚫 Failed ot create $SECRETS_DIR_NAME directory!"
fi
fi