Skip to content

Commit 7fd0b43

Browse files
authored
Safe file download (#79)
* Safe file download * Typo
1 parent f1d3125 commit 7fd0b43

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

patcher.sh

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,12 @@ function root_check() {
107107
function welcome_motd() {
108108
info "ffmpeg-patcher v$version"
109109

110-
motd=$(curl -s -L "$repo_base_url/$branch/motd.txt")
111-
if [ "${#motd}" -ge 1 ]; then
112-
log "Message of the day"
113-
echo ""
114-
echo "$motd"
115-
echo ""
116-
fi
110+
download "$repo_base_url/$branch/motd.txt" /tmp/tmp.wget
111+
112+
log "Message of the day"
113+
echo ""
114+
cat /tmp/tmp.wget
115+
echo ""
117116
}
118117

119118
function restart_packages() {
@@ -151,6 +150,22 @@ function check_dependencies() {
151150
fi
152151
}
153152

153+
function download() {
154+
wget -q -O - "$1" > /tmp/temp.wget
155+
downloadStatus=$?
156+
157+
if [[ $downloadStatus == 0 ]]; then
158+
mv -f /tmp/temp.wget "$2"
159+
else
160+
error "An error occurred while downloading $1. Rolling back changes..."
161+
unpatch
162+
163+
error "An error occurred while downloading $1, every changes were rolled back."
164+
error "Please check your internet connection / GithubStatus. If you think this is an error, please file an issue to the repository."
165+
exit 1
166+
fi
167+
}
168+
154169
################################
155170
# PATCH PROCEDURES
156171
################################
@@ -164,7 +179,7 @@ function patch() {
164179
mv -n "$vs_path/bin/$filename" "$vs_path/bin/$filename.orig"
165180

166181
info "Downloading and installing $filename's wrapper..."
167-
wget -q -O - "$repo_base_url/$branch/wrappers/$filename.sh" > "$vs_path/bin/$filename"
182+
download "$repo_base_url/$branch/wrappers/$filename.sh" "$vs_path/bin/$filename"
168183
chown root:VideoStation "$vs_path/bin/$filename"
169184
chmod 750 "$vs_path/bin/$filename"
170185
chmod u+s "$vs_path/bin/$filename"
@@ -191,9 +206,7 @@ function patch() {
191206

192207
for plugin in "${gstreamer_plugins[@]}"; do
193208
info "Downloading $plugin to gstreamer directory..."
194-
195-
wget -q -O - "$repo_base_url/$branch/plugins/$plugin.so" \
196-
> "$vs_path/lib/gstreamer/gstreamer-1.0/$plugin.so"
209+
download "$repo_base_url/$branch/plugins/$plugin.so" "$vs_path/lib/gstreamer/gstreamer-1.0/$plugin.so"
197210
done
198211

199212
mkdir -p "$vs_path/lib/gstreamer/dri"
@@ -202,9 +215,7 @@ function patch() {
202215

203216
for lib in "${gstreamer_libs[@]}"; do
204217
info "Downloading $lib to gstreamer directory..."
205-
206-
wget -q -O - "$repo_base_url/$branch/libs/$lib" \
207-
> "$vs_path/lib/gstreamer/$lib"
218+
download "$repo_base_url/$branch/libs/$lib" "$vs_path/lib/gstreamer/$lib"
208219
done
209220

210221
info "Saving current GSTOmx configuration..."

0 commit comments

Comments
 (0)