-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodify_gameinfo.sh
95 lines (71 loc) · 3.06 KB
/
modify_gameinfo.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
path_to_gameinfo_gi="$(dirname "$0")/game/csgo/gameinfo.gi"
target_line="Game csgo/addons/metamod"
debug=false # Set to true to enable debug messages
if [ -f "$path_to_gameinfo_gi" ]; then
lines=$(<"$path_to_gameinfo_gi")
found_metamod_game=false
found_game_lv=false
while IFS= read -r line; do
line=$(echo "$line" | tr -d '[:space:]')
if [ "$line" = "$target_line" ]; then
found_metamod_game=true
if [ "$debug" = true ]; then
echo "'$target_line' already exists in gameinfo.gi"
fi
break
fi
if echo "$line" | grep -q "Game_LowViolence\s\+csgo_lv"; then
if [ "$debug" = true ]; then
echo "Processing line: $line"
fi
found_game_lv=true
indentation=$(echo "$line" | sed -E 's/^(\s*).*/\1/')
target_line_with_indentation="$indentation$target_line"
if ! tail -n +$((i+1)) "$path_to_gameinfo_gi" | head -n 1 | grep -q "$target_line"; then
sed -i "/Game_LowViolence\s\+csgo_lv/ a $target_line_with_indentation" "$path_to_gameinfo_gi"
if [ "$debug" = true ]; then
echo "'$target_line' inserted after 'Game_LowViolence csgo_lv'"
fi
else
if [ "$debug" = true ]; then
echo "'$target_line' already exists after 'Game_LowViolence csgo_lv'"
fi
fi
found_metamod_game=true
break
fi
done <<< "$lines"
if ! $found_game_lv; then
if [ "$debug" = true ]; then
echo "'Game_LowViolence csgo_lv' not found in gameinfo.gi. Unable to insert '$target_line'."
fi
fi
if ! $found_metamod_game && $found_game_lv; then
last_game_lv_index=$(echo "$lines" | grep -n "Game_LowViolence\s\+csgo_lv" | tail -n 1 | cut -d':' -f1)
if [ "$last_game_lv_index" -ge 0 ]; then
indentation=$(echo "$lines" | sed -n "${last_game_lv_index}p" | sed -E 's/^(\s*).*/\1/')
target_line_with_indentation="$indentation$target_line"
sed -i "${last_game_lv_index} a $target_line_with_indentation" "$path_to_gameinfo_gi"
if [ "$debug" = true ]; then
echo "'$target_line' added after the last occurrence of 'Game_LowViolence csgo_lv'."
fi
else
if [ "$debug" = true ]; then
echo "'Game_LowViolence csgo_lv' not found in gameinfo.gi. Unable to insert '$target_line'."
fi
fi
fi
if $found_metamod_game || $found_game_lv; then
if [ "$debug" = true ]; then
echo "Modification completed successfully."
fi
else
if [ "$debug" = true ]; then
echo "No modifications made."
fi
fi
else
if [ "$debug" = true ]; then
echo "gameinfo.gi file not found at: $path_to_gameinfo_gi. Unable to proceed."
fi
fi