forked from TransparentLC/realesrgan-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
macos-build-script.sh
151 lines (134 loc) · 5.76 KB
/
macos-build-script.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Ask user whether to use mirror_head
read -p "Do you want to use mirror site to clone repo? (y/n): " use_mirror
if [ "$use_mirror" = "y" ]; then
mirror_head="https://mirror.ghproxy.com/"
else
mirror_head=""
fi
# Clone repo
echo "INFO: Clone repo."
repo_url="https://github.com/TransparentLC/realesrgan-gui.git"
git clone $mirror_head$repo_url
cd realesrgan-gui
# Create and activate Python virtual environment
echo "INFO: 🚧 Checking current Python version..."
python_version=$(python3 -V 2>&1 | cut -d" " -f2 | cut -d"." -f1-2)
if ! which python3 >/dev/null 2>&1; then
echo "ERROR: ⛔️ The 'python3' command not found."
echo "ERROR: 💬 Please check the Python environment configuration."
exit 1
else
echo "INFO: The 'python3' command found."
if [ "$python_version" == "3.12" ]; then
echo "INFO: ✅ The current Python version is 3.12"
echo "INFO: 🚧 Creating Python 3.12 virtual enviroment..."
python3 -m venv venv
echo "INFO: 🚧 Activating Python virtual enviroment..."
source venv/bin/activate
else
echo "ERROR: ⛔️ The current Python version is $python_version but 3.12 is required."
echo "INFO: 🚧 Installling Python package 'virtualenv'..."
pip3 install virtualenv
echo "INFO: 🚧 Creating Python 3.12 virtual enviroment..."
virtualenv -p python3.12 venv
echo "INFO: 🚧 Activating Python virtual enviroment..."
source venv/bin/activate
fi
fi
# Download extra files
# Function to download and process release asset
download_asset() {
repo=$1
asset_keyword=$2
unzip_target=$3
output_folder=$4
# GitHub API endpoint to retrieve releases
api_url="https://api.github.com/repos/$repo/releases/latest"
# Make a GET request to the GitHub API to retrieve the latest release
response=$(curl -s "$api_url")
# Check if repo is xinntao/Real-ESRGAN
if [ "$repo" = "xinntao/Real-ESRGAN" ]; then
asset_url="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-macos.zip"
zip_file=$(basename "$asset_url")
folder_name="models"
else
# Parse the response to get the latest release asset URL
asset_url=$(echo "$response" | grep -o "https://.*$asset_keyword*.zip" | head -n 1)
zip_file=$(basename "$asset_url")
folder_name=$(basename -s .zip "$zip_file")
fi
# Download the latest release asset
if [ -n "$asset_url" ]; then
echo "INFO: 🚧 Downloading $zip_file..."
curl -LO "$mirror_head$asset_url"
echo "INFO: ✅ Download $zip_file complete."
# Unzip and process the file
echo "INFO: 🚧 Extracting and processing files..."
unzip -j "$zip_file" "$folder_name/$unzip_target" -d "$output_folder"
# Perform additional actions based on the repo
if [ "$repo" = "upscayl/upscayl-ncnn" ]; then
# Thin file and set permissions
if [ -f "upscayl-bin" ]; then
# Thin file
arch=$(uname -m)
echo "INFO: 💬 System architecture is $arch."
echo "INFO: 🚧 Extracting architecture specific binary..."
target_file="upscayl-bin"
target_file_temp="upscayl-bin-temp"
if [ "$arch" = "arm64" ]; then
ditto --arch arm64 "$target_file" "$target_file_temp"
else
ditto --arch x86_64 "$target_file" "$target_file_temp"
fi
rm -rf "$target_file"
mv "$target_file_temp" "$target_file"
# Add execute permission
echo "INFO: 🚧 Setting execute permission to $target_file..."
chmod u+x $target_file
fi
elif [ "$repo" = "nihui/realsr-ncnn-vulkan" ]; then
# Rename RealSR models
if [ -f "models/x4.param" ] && [ -f "models/x4.bin" ]; then
echo "INFO: 🚧 Rename RealSR models..."
mv models/x4.param models/realsr-x4-realworld.param
mv models/x4.bin models/realsr-x4-realworld.bin
fi
elif [ "$repo" = "xinntao/Real-ESRGAN" ]; then
# Models to remove
models_to_remove=(
"realesr-animevideov3-x2"
"realesr-animevideov3-x3"
)
# Remove models
for model in "${models_to_remove[@]}"; do
param_file="models/$model.param"
bin_file="models/$model.bin"
if [ -f "$param_file" ] && [ -f "$bin_file" ]; then
echo "INFO: 🚧 Removing $model models..."
rm -rf "$param_file" "$bin_file"
fi
done
fi
echo "INFO: ✅ Processing complete."
else
echo "ERROR: ⛔️ No release asset found for $repo."
fi
}
# Download and process assets for upscayl-ncnn
download_asset "upscayl/upscayl-ncnn" "macos" "upscayl-bin" "."
# Download and process assets for realsr-ncnn-vulkan
download_asset "nihui/realsr-ncnn-vulkan" "macos" "models-DF2K/*" "models"
# Download and process assets for realesrgan-ncnn-vulkan
download_asset "xinntao/Real-ESRGAN" "macos" "*" "models"
# Install dependencies
echo "INFO: 🚧 Installing requirements..."
pip3 install -r requirements.txt
echo "INFO: 🚧 Installing Python package 'pyinstaller'..."
pip install pyinstaller
# Build macOS app
echo "INFO: 🚧 Packaging macOS app..."
sudo pyinstaller realesrgan-gui-macos.spec
# Copy built app to Download directory
ditto dist/Real-ESRGAN\ GUI.app $HOME/Downloads/Real-ESRGAN\ GUI.app
echo "INFO: ✅ 'Real-ESRGAN GUI.app' is in Downloads directory."
echo "INFO: 💬 Please manually drag 'Real-ESRGAN GUI.app' to Applications directory to finish install."