-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre_open
executable file
·123 lines (77 loc) · 2.55 KB
/
pre_open
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
FILE_RC=""
HERE=$(pwd)
DIR_HOME=$(eval echo ~"$USER")
FILE_ZSH_RC="$DIR_HOME/.zshrc"
FILE_BASH_RC="$DIR_HOME/.bashrc"
if test -e "$FILE_ZSH_RC"; then
FILE_RC="$FILE_ZSH_RC"
else
if test -e "$FILE_BASH_RC"; then
FILE_RC="$FILE_BASH_RC"
else
echo "ERROR: No '$FILE_ZSH_RC' or '$FILE_BASH_RC' found on the system"
exit 1
fi
fi
if [ -z "$SUBMODULES_HOME" ]; then
echo "WARNING: The 'SUBMODULES_HOME' variable is not defined"
export SUBMODULES_HOME="$DIR_HOME/Apps/Project-Toolkit"
echo "The 'SUBMODULES_HOME' variable is exported: '$SUBMODULES_HOME'"
fi
if [ -z "$SUBMODULES_HOME" ]; then
echo "ERROR: The 'SUBMODULES_HOME' variable is not defined"
exit 1
fi
# shellcheck disable=SC2002
if ! cat "$FILE_RC" | grep "SUBMODULES_HOME=" >/dev/null 2>&1; then
echo "The 'SUBMODULES_HOME' has not been exported in '$FILE_RC'"
if echo "" >> "$FILE_RC" && echo "export SUBMODULES_HOME=$SUBMODULES_HOME" >> "$FILE_RC"; then
echo "SUBMODULES_HOME is added into '$FILE_RC' configuration"
# shellcheck disable=SC1090
. "$FILE_RC"
else
echo "ERROR: SUBMODULES_HOME was not added into '$FILE_RC' configuration"
exit 1
fi
fi
FILES_COUNT=0
if test -e "$SUBMODULES_HOME"; then
# shellcheck disable=SC2012
FILES_COUNT=$(ls "$SUBMODULES_HOME" -1 | wc -l)
fi
if [ "$FILES_COUNT" = "0" ]; then
SESSION=$(($(date +%s%N)/1000000))
DIR_TMP="$HERE/_Tmp/$SESSION"
if ! test -e "$DIR_TMP"; then
if ! mkdir -p "$DIR_TMP"; then
echo "ERROR: Could not create tmp directory '$DIR_TMP'"
exit 1
fi
fi
if cd "$DIR_TMP" && wget "https://raw.githubusercontent.com/red-elf/Project-Toolkit/main/clone?append=$SESSION" -O clone; then
echo "Clone script is ready"
if chmod +x ./clone && ./clone [email protected]:red-elf/Project-Toolkit.git ./Toolkit; then
cd "$HERE" && rm -rf "$DIR_TMP" && echo "Project Toolkit is installed to '$SUBMODULES_HOME'"
else
echo "ERROR: Project Toolkit is not installed to '$SUBMODULES_HOME' (2)"
exit 1
fi
else
echo "ERROR: Project Toolkit is not installed to '$SUBMODULES_HOME' (1)"
exit 1
fi
fi
DIR_MODULE_UPSTREAMABLE="$SUBMODULES_HOME/Upstreamable"
SCRIPT_PATHS="$SUBMODULES_HOME/Software-Toolkit/Utils/Sys/paths.sh"
if ! test -e "$SCRIPT_PATHS"; then
echo "ERROR: Prepare script not found '$SCRIPT_PATHS'"
exit 1
fi
# shellcheck disable=SC1090
. "$SCRIPT_PATHS"
ADD_TO_PATH "$FILE_RC" "$DIR_MODULE_UPSTREAMABLE"
# shellcheck disable=SC1090
. "$FILE_RC"
BRAND_IDE=true
export BRAND_IDE