Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat): add autoupdate functionality #88

Merged
merged 11 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Dockerfile.ubuntu18
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN curl -O https://dl.winehq.org/wine-builds/winehq.key
RUN apt-key add winehq.key
RUN add-apt-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ bionic main'
RUN apt-get update
RUN apt-get install -y winehq-stable
RUN apt-get install -y winehq-stable=8.0.1*

RUN apt-get install -y winetricks

Expand All @@ -26,11 +26,13 @@ RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
ENV LANG en_US.UTF-8

ENV APP_NAME="Backblaze Personal Backup"
ENV FORCE_LATEST_UPDATE="false"
ENV DISABLE_AUTOUPDATE="false"

# Disable WINE Debug messages
ENV WINEDEBUG -all

EXPOSE 5900

COPY startapp.sh /startapp.sh
COPY startapp.sh PINNED_BZ_VERSION RELEASE_VERSION /
RUN chmod +x /startapp.sh
6 changes: 4 additions & 2 deletions Dockerfile.ubuntu20
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN curl -O https://dl.winehq.org/wine-builds/winehq.key
RUN apt-key add winehq.key
RUN add-apt-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ focal main'
RUN apt-get update
RUN apt-get install -y winehq-stable
RUN apt-get install -y winehq-stable=8.0.2*

RUN apt-get install -y winetricks

Expand All @@ -26,11 +26,13 @@ RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
ENV LANG en_US.UTF-8

ENV APP_NAME="Backblaze Personal Backup"
ENV FORCE_LATEST_UPDATE="false"
ENV DISABLE_AUTOUPDATE="false"

# Disable WINE Debug messages
ENV WINEDEBUG -all

EXPOSE 5900

COPY startapp.sh /startapp.sh
COPY startapp.sh PINNED_BZ_VERSION RELEASE_VERSION /
RUN chmod +x /startapp.sh
6 changes: 4 additions & 2 deletions Dockerfile.ubuntu22
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN curl -O https://dl.winehq.org/wine-builds/winehq.key
RUN apt-key add winehq.key
RUN add-apt-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ jammy main'
RUN apt-get update
RUN apt-get install -y winehq-stable
RUN apt-get install -y winehq-stable=8.0.2*

RUN apt-get install -y winetricks

Expand All @@ -26,11 +26,13 @@ RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
ENV LANG en_US.UTF-8

ENV APP_NAME="Backblaze Personal Backup"
ENV FORCE_LATEST_UPDATE="false"
ENV DISABLE_AUTOUPDATE="false"

# Disable WINE Debug messages
ENV WINEDEBUG -all

EXPOSE 5900

COPY startapp.sh /startapp.sh
COPY startapp.sh PINNED_BZ_VERSION RELEASE_VERSION /
RUN chmod +x /startapp.sh
2 changes: 2 additions & 0 deletions PINNED_BZ_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
9.0.0.749
https://web.archive.org/web/20231218152237/https://secure.backblaze.com/win32/install_backblaze.exe
1 change: 1 addition & 0 deletions RELEASE_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.6
169 changes: 159 additions & 10 deletions startapp.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,165 @@
#!/bin/sh
set -x
if [ -f "/config/wine/drive_c/Program Files (x86)/Backblaze/bzbui.exe" ]
then

# Define globals
release_version=$(cat "/RELEASE_VERSION") #backblaze-personal-wine version tag
local_version_file="$WINEPREFIX/dosdevices/c:/ProgramData/Backblaze/bzdata/bzreports/bzserv_version.txt"
install_exe_path="$WINEPREFIX/dosdevices/c:/"
log_file="$WINEPREFIX/dosdevices/c:/backblaze-wine-startapp.log"
custom_user_agent="backblaze-personal-wine/$release_version (JonathanTreffler, +https://github.com/JonathanTreffler/backblaze-personal-wine-container), CFNetwork"

# Extracting variables from the PINNED_VERSION file
pinned_bz_version_file="/PINNED_BZ_VERSION"
pinned_bz_version=$(sed -n '1p' "$pinned_bz_version_file")
pinned_bz_version_url=$(sed -n '2p' "$pinned_bz_version_file")

export WINEARCH="win64"

# Disclaimer
disclaimer_updatemode() {
# Check if auto-updates are disabled
if [ "$DISABLE_AUTOUPDATE" = "true" ]; then
echo "Auto-updates are disabled. Backblaze won't be updated."
else
# Check the status of FORCE_LATEST_UPDATE
if [ "$FORCE_LATEST_UPDATE" = "true" ]; then
echo "FORCE_LATEST_UPDATE is enabled which may brick your installation."
else
echo "FORCE_LATEST_UPDATE is disabled. Using known-good version of Backblaze."
fi
fi
}

disclaimer_updatemode


if [ -f "/config/wine/drive_c/Program Files (x86)/Backblaze/bzbui.exe" ]; then
# Function to handle errors
handle_error() {
echo "Error: $1" >> "$log_file"
start_app # Start app even if there is a problem with the updater
}

log_message() {
echo "$(date): $1" >> "$log_file"
}

start_app() {
log_message "STARTAPP: Starting Backblaze version $local_version_file"
wine64 "/config/wine/drive_c/Program Files (x86)/Backblaze/bzbui.exe" -noqiet &
sleep infinity
}

check_url_validity() {
url="$1"
if http_code=$(curl -s -o /dev/null -w "%{http_code}" "$url"); then
if [ "$http_code" -eq 200 ]; then
content_type=$(curl -s -I "$url" | grep -i content-type | cut -d ':' -f2)
if echo "$content_type" | grep -q "xml"; then
return 0 # Valid XML content found
fi
fi
fi
return 1 # Invalid or unavailable content
}

compare_versions() {
local_version="$1"
compare_version="$2"

if dpkg --compare-versions "$local_version" lt "$compare_version"; then
log_message "UPDATER: COMPARE: newer version found - local $local_version - remote $compare_version"
return 0 # The compare_version is higher
else
log_message "UPDATER: COMPARE: no new version found - local $local_version - remote $compare_version"
return 1 # The local version is higher or equal
fi
}

fetch_and_install() {
cd "$install_exe_path" || handle_error "UPDATER: can't navigate to $install_exe_path"
if [ "$FORCE_LATEST_UPDATE" = "true" ]; then
log_message "UPDATER: FORCE_LATEST_UPDATE=true - downloading latest version"
curl -L "https://www.backblaze.com/win32/install_backblaze.exe" --output "install_backblaze.exe"
else
log_message "UPDATER: FORCE_LATEST_UPDATE=false - downloading known-good version from archive.org"
curl -A "$custom_user_agent" -L "$pinned_bz_version_url" --output "install_backblaze.exe"
fi
log_message "UPDATER: Starting install_backblaze.exe"
WINEARCH="$WINEARCH" WINEPREFIX="$WINEPREFIX" wine64 "./install_backblaze.exe" || handle_error "UPDATER: Failed to install Backblaze"
}

# Check if auto-updates are disabled
if [ "$DISABLE_AUTOUPDATE" = "true" ]; then
log_message "UPDATER: DISABLE_AUTOUPDATE=true, Auto-updates are disabled. Starting Backblaze without updating."
start_app
fi

# Update process for force_latest_update set to true or not set
if [ "$FORCE_LATEST_UPDATE" = "true" ]; then
# Main auto update logic
if [ -f "$local_version_file" ]; then
log_message "UPDATER: FORCE_LATEST_UPDATE=true, updating to the latest version"
urls="
https://ca000.backblaze.com/api/clientversion.xml
https://ca001.backblaze.com/api/clientversion.xml
https://ca002.backblaze.com/api/clientversion.xml
https://ca003.backblaze.com/api/clientversion.xml
https://ca004.backblaze.com/api/clientversion.xml
https://ca005.backblaze.com/api/clientversion.xml
"

for url in $urls; do
if check_url_validity "$url"; then
xml_content=$(curl -s "$url") || handle_error "UPDATER: Failed to fetch XML content"
xml_version=$(echo "$xml_content" | grep -o '<update win32_version="[0-9.]*"' | cut -d'"' -f2)
local_version=$(cat "$local_version_file") || handle_error "UPDATER: Failed to read local version from $local_version_file"

if compare_versions "$local_version" "$xml_version"; then
log_message "UPDATER: Newer version found - downloading and installing the newer version..."
fetch_and_install
start_app # Exit after successful download+installation and start app
else
log_message "UPDATER: The installed version is up to date."
start_app # Exit autoupdate and start app
fi
fi
done

handle_error "No valid XML content found or all URLs are unavailable."
else
handle_error "Local version file not found. Exiting."
fi
else
# Update process for force_latest_update set to false or anything else
if [ -f "$local_version_file" ]; then
log_message "UPDATER: FORCE_LATEST_UPDATE=false, Checking if newer version than $local_version_file is available."
local_version=$(cat "$local_version_file") || handle_error "UPDATER: Failed to read local version file"

if compare_versions "$local_version" "$pinned_bz_version"; then
log_message "UPDATER: FORCE_LATEST_UPDATE=false, Newer version found - downloading and installing the newer version..."
fetch_and_install
start_app # Exit after successful download+installation and start app
else
log_message "UPDATER: FORCE_LATEST_UPDATE=false, The local version is up to date. There may be a newer version available when using FORCE_LATEST_UPDATE=true"
start_app # Exit autoupdate and start app
fi
else
handle_error "UPDATER: Local version file does not exist. Exiting updater."
fi
fi
else
mkdir /config/wine/
cd /config/wine/
curl -L "https://www.backblaze.com/win32/install_backblaze.exe" --output "install_backblaze.exe"
ls -la
wine64 "install_backblaze.exe" &
#sleep 10
#ln -s /drive_d/ /config/wine/dosdevices/d:
mkdir -p /config/wine/ &&
if [ "$FORCE_LATEST_UPDATE" = "true" ]; then
log_message "INSTALLER: FORCE_LATEST_UPDATE=true, Installing latest Backblaze version"
curl -L "https://www.backblaze.com/win32/install_backblaze.exe" --output "install_backblaze.exe" &&
ls -la &&
wine64 "install_backblaze.exe" &
else
log_message "INSTALLER: FORCE_LATEST_UPDATE=false, Installing pinned Backblaze version"
curl -A "$custom_user_agent" -L "$pinned_bz_version_url" --output "install_backblaze.exe"&&
ls -la &&
wine64 "install_backblaze.exe" &
fi
sleep infinity
fi
fi
Loading