-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
update.sh
65 lines (52 loc) · 2.05 KB
/
update.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
#!/bin/bash
if ! command -v unzip &> /dev/null; then
echo "unzip could not be found, run sudo apt-get install unzip to install it."
exit 1
fi
# Function to get the latest release version from GitHub
get_latest_release_version() {
apiUrl="https://api.github.com/repos/skier233/nsfw_ai_model_server/releases/latest"
latestRelease=$(curl -s $apiUrl | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
echo $latestRelease
}
# Function to read the local version from config.yaml
get_local_version() {
configPath="./config/version.yaml"
if [[ -f "$configPath" ]]; then
localVersion=$(grep 'VERSION:' $configPath | awk '{print $2}')
echo $localVersion
else
echo "null"
fi
}
latestVersion=$(get_latest_release_version)
localVersion=$(get_local_version)
if [[ "$latestVersion" == "$localVersion" ]]; then
echo "You are up to date. Current version: $localVersion"
exit 0
fi
echo "Updating to latest version: $latestVersion from $localVersion"
download="https://github.com/skier233/nsfw_ai_model_server/releases/latest/download/nsfw_ai_model_server.zip"
zip="nsfw_ai_model_server.zip"
tempDir="temp_nsfw_ai_model_server"
echo "Downloading latest release"
wget -O $zip $download
echo "Extracting release files to temporary directory"
mkdir -p $tempDir
unzip -o $zip -d $tempDir
# Delete /config/config.yaml if it exists in the temporary directory
configFilePath="$tempDir/config/config.yaml"
if [ -f "$configFilePath" ]; then
echo "Deleting config.yaml from temporary directory to preserve existing configuration"
rm -f "$configFilePath"
fi
echo "Copying files to the current directory"
rsync -av --exclude='update.sh' $tempDir/* . || { echo "Failed to copy files."; exit 1; }
echo "Cleaning up"
rm -v -f $zip || { echo "Failed to remove the zip file."; exit 1; }
rm -v -rf $tempDir || { echo "Failed to remove the temporary directory."; exit 1; }
echo "Update complete"
# Activate conda environment and update
conda activate ai_model_server
pip uninstall ai-processing -y
conda env update --file ./environment-linux.yml