Welcome to mirror list, hosted at ThFree Co, Russian Federation.

install-uvtools.sh « Scripts - github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d8332b23ad38a6adcced18b6a0392214d28afc90 (plain)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/bin/bash
#
# Script to download and install/upgrade UVtools in current location
# Can be run outside UVtools and as standalone script
# Then run this script
# usage 1: ./install-uvtools.sh
#

#cd "$(dirname "$0")"
arch="$(uname -m)" # x86_64 or arm64
archCode="${arch/86_/}"
osVariant=""       # osx, linux, arch, rhel
api_url="https://api.github.com/repos/sn4k3/UVtools/releases/latest"
dependencies_url="https://raw.githubusercontent.com/sn4k3/UVtools/master/Scripts/install-dependencies.sh"
macOS_least_version=10.15

version() { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
testcmd() { command -v "$1" &> /dev/null; }
get_filesize() {
    (
      du --apparent-size --block-size=1 "$1" 2>/dev/null ||
      gdu --apparent-size --block-size=1 "$1" 2>/dev/null ||
      find "$1" -printf "%s" 2>/dev/null ||
      gfind "$1" -printf "%s" 2>/dev/null ||
      stat --printf="%s" "$1" 2>/dev/null ||
      stat -f%z "$1" 2>/dev/null ||
      wc -c <"$1" 2>/dev/null
    ) | awk '{print $1}'
}
downloaduvtools(){
    if [ -z "$1" ]; then
        echo "Download url was not specified"
        exit -1
    fi

    filename="$(basename "${download_url}")"
    tmpfile="$(mktemp "${TMPDIR:-/tmp}"/UVtoolsUpdate.XXXXXXXX)"

    echo "Downloading: $download_url"
    curl -L --retry 4 $download_url -o "$tmpfile"

    download_size="$(curl -sLI $download_url | grep -i Content-Length | awk 'END{print $2}' | tr -d '\r')"
    if [ -n "$download_size" ]; then
        echo "- Validating file"
        local filesize="$(get_filesize "$tmpfile")"
        if [ "$download_size" -ne "$filesize" ]; then
            echo "Error: File verification failed, expecting $download_size bytes but downloaded $filesize bytes. Please re-run the script."
            rm -f "$tmpfile"
            exit -1
        fi
    fi

    echo "- Kill instances"
    killall UVtools 2> /dev/null
    ps -ef | grep '.*dotnet.*UVtools.dll' | grep -v grep | awk '{print $2}' | xargs kill 2> /dev/null
    sleep 0.5
}

if [ "$arch" != "x86_64" -a "$arch" != "arm64" ]; then
    echo "Error: Unsupported host arch $arch"
    exit -1
fi

echo "Script to download and install UVtools"

echo "- Detecting OS"

if [ "${OSTYPE:0:6}" == "darwin" ]; then
    #############
    #   macOS   #
    #############
    osVariant="osx"
    macOS_version="$(sw_vers -productVersion)"
    appPath="/Applications/UVtools.app"

    echo "- Detected: $osVariant $arch"

    if [ $(version $macOS_version) -lt $(version $macOS_least_version) ]; then
        echo "Error: Unable to install, UVtools requires at least macOS $macOS_least_version."
        exit -1
    fi

    # Required dotnet-sdk to run arm64 and bypass codesign
    if [ "$arch" == "arm64" -a -z "$(command -v dotnet)" ]; then
        if ! testcmd brew; then
            bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
            if [ -f "/opt/homebrew/bin/brew" -a -z "$(command -v brew)" ]; then
                echo '# Set PATH, MANPATH, etc., for Homebrew.' >> "$HOME/.zprofile"
                echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> "$HOME/.zprofile"
                eval "$(/opt/homebrew/bin/brew shellenv)"
            fi
        fi

        brew install --cask dotnet-sdk
    fi

    echo "- Detecting download"

    download_url="$(curl -s "$api_url" \
    | grep "browser_download_url.*_${osVariant}-${archCode}_.*\.zip" \
    | head -1 \
    | cut -d : -f 2,3 \
    | tr -d \")"

    if [ -z "$download_url" ]; then
        echo "Error: Unable to detect the download url."
        exit -1
    fi

    downloaduvtools "$download_url"

    echo "- Removing old versions"
    rm -rf "$appPath"

    echo "- Inflating $filename to $appPath"
    unzip -q -o "$tmpfile" -d "/Applications"
    rm -f "$tmpfile"

    if [ -d "$appPath" ]; then
        # Remove quarantine security from files
        find "$appPath" -print0 | xargs -0 xattr -d com.apple.quarantine &> /dev/null

        echo ''
        echo 'Installation was successful. UVtools will now run.'

        # arm64: Create script on user desktop to run UVtools
        if [ "$arch" == "arm64" ]; then
            run_script="$HOME/Desktop/run-uvtools"

            echo '#!/bin/bash
# Run this script to run UVtools on macOS arm64 machines
cd "$(dirname "$0")"

lookupPaths=(
    "/Applications/UVtools.app/Contents/MacOS/UVtools.sh"
    "UVtools.app/Contents/MacOS/UVtools.sh"
    "$HOME/Desktop/UVtools.app/Contents/MacOS/UVtools.sh"
    "$HOME/Downloads/UVtools.app/Contents/MacOS/UVtools.sh"
    "$HOME/UVtools.app/Contents/MacOS/UVtools.sh"
)

for path in "${lookupPaths[@]}"
do
    if [ -f "$path" ]; then
        echo "Found: $path"
        echo "UVtools will now run."

        nohup bash "$path" &> /dev/null &
        disown
        
        echo "You can close this terminal window."
        exit
    fi
done

echo "Error: UVtools.app not found on known paths"
' > "$run_script"

            chmod 775 "$run_script"
            echo 'Note: Always run "bash run-uvtools" from your Desktop to launch UVtools on this Mac (arm64)!'
        fi

        echo ''

        if [ "$arch" == "arm64" -a -f "$appPath/Contents/MacOS/UVtools.sh" ]; then
            nohup bash "$appPath/Contents/MacOS/UVtools.sh" &> /dev/null &
            disown
        elif [ -d "$appPath" ]; then
            open -n "$appPath"
        fi
    else
        echo "Installation unsuccessful, unable to create '$appPath'."
        exit -1
    fi

    exit 1
elif testcmd apt-get; then
    osVariant="linux"
    [ -z "$(command -v curl)" ] && sudo apt-get install -y curl
elif testcmd pacman; then
    osVariant="arch"
    [ -z "$(command -v curl)" ] && sudo pacman -S curl
elif testcmd dnf; then
    osVariant="rhel"
    [ -z "$(command -v curl)" ] && sudo dnf install -y curl
fi

if [ -z "$osVariant" ]; then
    echo "Error: Unable to detect your Operative System."
    exit -1
fi

#############
#   Linux   #
#############
echo "- Detected: $osVariant $arch"

requiredlddversion="2.31"
lddversion="$(ldd --version | awk '/ldd/{print $NF}')"


if [ $(version $lddversion) -lt $(version $requiredlddversion) ]; then
    echo ""
    echo "##########################################################"
    echo "Error: Unable to auto install the latest version."    
    echo "ldd version: $lddversion detected, but requires at least version $requiredlddversion."
    echo "Solutions:"
    echo "- Upgrade your system to the most recent version"
    echo "- Try to upgrade glibc to at least $requiredlddversion (Search about this as it can break your system)"
    echo "##########################################################"
    exit -1
fi

if testcmd ldconfig; then
    if [ -z "$(ldconfig -p | grep libpng)" -o -z "$(ldconfig -p | grep libgdiplus)" -o -z "$(ldconfig -p | grep libgeotiff)" ]; then
        echo "- Missing dependencies found, installing..."
        sudo bash -c "$(curl -fsSL $dependencies_url)"
    fi
else
    echo "Unable to detect for missing dependencies, ldconfig not found, however installation will continue."
fi

echo "- Detecting download"
response="$(curl -s "$api_url")"

download_url="$(echo "$response" \
| grep "browser_download_url.*_${osVariant}-x64_.*\.AppImage" \
| head -1 \
| cut -d : -f 2,3 \
| tr -d \")"

if [ -z "$download_url" ]; then
    download_url="$(echo "$response" \
    | grep "browser_download_url.*_linux-x64_.*\.AppImage" \
    | head -1 \
    | cut -d : -f 2,3 \
    | tr -d \")"
fi

if [ -z "$download_url" ]; then
    echo "Error: Unable to detect the download url."
    exit -1
fi

downloaduvtools "$download_url"

targetDir="$PWD"
[ -d "$HOME/Applications" ] && targetDir="$HOME/Applications"
targetFilePath="$targetDir/UVtools.AppImage"

echo "- Removing old versions"
rm -f "$targetDir/UVtools_"*".AppImage"

echo "- Moving $filename to $targetDir"
mv -f "$tmpfile" "$targetFilePath"
rm -f "$tmpfile"

echo "- Setting permissions"
chmod -fv 775 "$targetFilePath"

"$targetFilePath" &

echo ''
echo 'Installation was successful. UVtools will now run.'
echo 'If prompt for "Desktop integration", click "Integrate and run"'
echo ''