Repository navigation
Expand file tree
/
Copy pathupdate.sh
More file actions
130 lines (116 loc) · 5.04 KB
/
Copy pathupdate.sh
File metadata and controls
130 lines (116 loc) · 5.04 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
cat storage/logo | sed 's/ Version: {VERSION}//'
VERSION=$(cat version)
FULL_REWRITE="false"
check_skipped_update() {
local current_version="$1"
local latest_version="$2"
local url="https://raw.githubusercontent.com/K3YOMI/AtmosphericX/refs/heads/main/changelogs-history.json"
changelog_data=$(curl -s -f "$url")
skipped_rewrites=()
found_rewrite="false"
versions=()
mapfile -t versions < <(echo "$changelog_data" | grep '"version"' | sed 's/.*: "\(.*\)".*/\1/' | sort -V)
for version in "${versions[@]}"; do
if [[ "$(printf "%s\n%s" "$current_version" "$version" | sort -V | head -n 1)" == "$current_version" ]] &&
[[ "$(printf "%s\n%s" "$version" "$latest_version" | sort -V | head -n 1)" == "$version" ]]; then
rewrite_flag=$(echo "$changelog_data" | awk -v ver="\"$version\"" '
$0 ~ ver {found=1}
found && /"rewrite":/ {print $2; exit}' | tr -d ',')
if [[ "$rewrite_flag" == "true" ]]; then
skipped_rewrites+=("$version")
found_rewrite="true"
fi
fi
done
if [ "$found_rewrite" = "true" ]; then
echo "[WARNING] You skipped a version that required a full rewrite!"
echo "Skipped versions requiring rewrites: ${skipped_rewrites[*]}"
echo "[INFO] The update process will enforce a full rewrite."
FULL_REWRITE="true"
else
echo "[INFO] No skipped full rewrites detected."
fi
}
fetch_changelogs() {
local version="$1"
local url="https://raw.githubusercontent.com/K3YOMI/AtmosphericX/refs/heads/main/changelogs-history.json"
local new_version="https://raw.githubusercontent.com/k3yomi/AtmosphericX/main/version"
new_version=$(curl -s -f "$new_version")
if [ "$version" != "$new_version" ]; then
echo "Your current version: $version"
echo "A newer version is available: $new_version"
else
echo "You are already on the latest version: $version"
fi
changelog=$(curl -s -f "$url" | awk -v ver="\"$new_version\"" 'BEGIN { found=0 }$1 ~ ver":" { found=1 }found && /^\s*}/ { exit }found { print }')
echo ============================ LATEST VERSION ============================
if [ -n "$changelog" ]; then
updated=$(echo "$changelog" | grep '"updated"' | sed 's/.*: "\(.*\)".*/\1/')
ver=$(echo "$changelog" | grep '"version"' | sed 's/.*: "\(.*\)".*/\1/')
headline=$(echo "$changelog" | grep '"headline"' | sed 's/.*: "\(.*\)".*/\1/')
changelogs=$(echo "$changelog" | awk '/"changelogs"/,/\]/' | grep -o '"[^"]\+"' | sed 's/"//g')
rewrite=$(echo "$changelog" | grep '"rewrite"' | sed 's/.*: \(.*\),*/\1/' | tr -d ' ')
echo "Version: v$ver"
echo "Updated: $updated"
echo "Full Rewrite Required: $rewrite"
FULL_REWRITE=$rewrite
FULL_REWRITE=$(echo "$FULL_REWRITE" | tr -d '\r' | xargs)
if [ -n "$headline" ] && [ "$headline" != "null" ]; then
echo "Headline: $headline"
fi
if [ -n "$changelogs" ]; then
echo "Changelogs:"
echo "$changelogs" | while read -r line; do
echo " - $line"
done
else
echo "No changelogs available for this version."
fi
else
echo "No changelogs available for this version."
fi
echo =============================== END OF LOG ==============================
}
run_installer() {
cd project_atmospheric_x
rm -rf node_modules package-lock.json
npm install . --silent --no-save
npm install atmosx-nwws-parser@latest --silent --no-save
npm install atmosx-tempest-pulling@latest --silent --no-save
npm install atmosx-placefile-parser@latest --silent --no-save
}
commit_update() {
if [ "$FULL_REWRITE" = "true" ]; then
echo "[INFO] A backup of your configurations will be created in configurations.bak"
echo "[WARNING] This update requires a full rewrite of your configurations and project files."
echo "Would you like to proceed? (y/n)"
read -r answer
if [ "$answer" = "y" ]; then
echo "Backing up old configuration file..."
cp -r configurations.json configurations.bak
echo "[INFO] Configuration file backed up in configurations.bak"
git fetch --all
git reset --hard origin/main
run_installer
else
echo "[INFO] Exiting updater..."
exit 0
fi
else
echo "[INFO] Updating files..."
git fetch --all
files_to_update=$(git diff --name-only origin/main | grep -v -E 'update\.sh|configurations\.bak|configurations\.json')
for file in $files_to_update; do
echo "Updating $file..."
git checkout origin/main -- "$file"
done
run_installer
fi
echo "[INFO] Update complete. Please restart the application to apply changes."
}
# Run the update process
fetch_changelogs "$VERSION"
check_skipped_update "$VERSION"
commit_update
read -p "Press enter to continue..."