-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell-env
More file actions
105 lines (90 loc) · 2.49 KB
/
shell-env
File metadata and controls
105 lines (90 loc) · 2.49 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
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
#!/bin/bash
# user level apps
export LOCAL_PATH="${HOME}/local"
export LOCAL_BIN_PATH="${LOCAL_PATH}/bin"
mkdir -p $LOCAL_BIN_PATH
# user level python
PY_VERSION="${PY_VERSION:-3.13}"
PY_EXEC="python${PY_VERSION}"
PY_HOME="${HOME}/.py${PY_VERSION}"
PIP_EXEC="pip${PY_VERSION}"
# colors
export COLOR_RED='\033[0;31m'
export COLOR_YELLOW='\033[1;33m'
export COLOR_GREEN='\033[0;32m'
export COLOR_BLUE='\033[1;34m'
export COLOR_CYAN='\033[0;36m'
export COLOR_LIGHT_RED='\033[1;31m'
export COLOR_NONE='\033[0m'
check_platform (){
if [[ "$OSTYPE" == "linux"* ]]; then
distro_id=`lsb_release -d`
if [[ "$distro_id" == *"Debian"* ]] || [[ "$distro_id" == *"Ubuntu"* ]]; then
export os_platform="debian"
export AWK_EXEC="awk"
export SED_EXEC="sed"
else
echo "Unsupported Linux distro: $distro_id"
exit 1
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
export os_platform="osx"
export AWK_EXEC="gawk"
export SED_EXEC="gsed"
fi
}
check_platform
user_confirm (){
prompt="${1}"
defval="${2:-n}"
read -p "$(echo -e "${COLOR_BLUE}${prompt} Continue? (y/n)${COLOR_NONE} ")" -n 1 -r confirm_result
echo
if [[ $confirm_result != "y" ]] && [[ $confirm_result != "Y" ]]; then
exit 1
fi
}
insert_line (){
target_file="$1"
line="$2"
touch "$target_file"
if ! grep -q "^$line$" "$target_file" ; then
echo >> "$target_file"
echo "$line" >> "$target_file"
fi
}
insert_file (){
source_file="$1"
target_file="$2"
start_marker="$3"
end_marker="$4"
[[ ! -f "$source_file" ]] && echo "Source file not found: $source_file" && exit 1
touch "$target_file"
cp $target_file "$target_file.bak"
if grep -q "^$start_marker$" "$target_file" && grep -q "^$end_marker$" "$target_file"; then
gawk "/^$start_marker$/,/^$end_marker$/ {
if (/^$start_marker$/) {
print;
while ((getline line < \"$source_file\") > 0) {
print line
}
close(\"$source_file\")
next
}
if (/^$end_marker$/) {
print;
next
}
next
}
{print}" "$target_file.bak" >"$target_file"
else
{ echo;
echo "$start_marker";
cat "$source_file";
echo "$end_marker"; } >> "$target_file"
fi
}
set -e
if [ ! -z "$debug" ]; then
set -x
fi