ungoogled-software / ungoogled-chromium

Google Chromium, sans integration with Google
BSD 3-Clause "New" or "Revised" License
20.76k stars 842 forks source link

Auto update #2357

Closed ghost closed 1 year ago

ghost commented 1 year ago

Description

Create a script for automatic binary update.

Who's implementing?

The problem

I use the portable version of the https://github.com/clickot/ungoogled-chromium-binaries

It is tedious to have to manually update the binaries, so I have created a script to do it automatically.

The problem is that my bash/shell skills are limited and while it may be a solution for me I'm not sure I can maintain a stable version.

The idea is to create a wrapper in bash that checks for new updates. I share my script.

Possible solutions

My installation is in "/opt/ungoogled" so to run the browser I do "/opt/ungoogled/chrome-wrapper" I have created a second script as a wrapper "chrome-wrapper-updater":

#!/bin/bash

./updater >> ./updater.log &
./chrome-wrapper "$@"

So to run the browser I do: /opt/ungoogled/chrome-wrapper-updater

The code of the "updater" script is as follows:

#!/bin/bash

echo $(date)

DIR_INSTALL="/opt/ungoogled"
DIR_TMP="./tmp"
DIR_TMP_UPDATER="${DIR_TMP}/ungoogled-chromium-updater"
FILE_CURRENT_VER="./updater-current-version"
FILE_LAST_CHECK="./updater-last-check"
REPO_URL="https://api.github.com/repos/clickot/ungoogled-chromium-binaries/releases/latest"
REPO_KEY=".assets[].browser_download_url"
REPO_TYPE="linux.tar.xz"
REPO_LINK=""
REPO_VER=""
CURRENT_VER=$(head -n 1 $FILE_CURRENT_VER)
NOW=$(date +%s)
EVERY=$((60 * 60 * 24 * 7))
LAST_CHECK=$(head -n 1 $FILE_LAST_CHECK)
NEXT_CHECK=$(($LAST_CHECK + $EVERY))

if [[ $NOW -gt $NEXT_CHECK ]]; then
    echo "Check new version"
    REPO_LINK=$(curl ${REPO_URL} | jq -r ${REPO_KEY} | grep ${REPO_TYPE})
    REPO_VER=$(awk -F "/" '{print $(NF-1)}' <<< "$REPO_LINK")
    echo $NOW > $FILE_LAST_CHECK

    if [ $CURRENT_VER != $REPO_VER ]; then
        echo "Has new version: ${REPO_VER}"
        kdialog --title "Ungoogled Chromium Update" \
                --yesno "New version (${REPO_VER})\nUPDATE?" 0 0
        ans=$?
        if [ $ans -eq 0 ]
        then
            echo "User accepts the update: ${REPO_VER}"
            mkdir -p ${DIR_TMP}
            rm -r ${DIR_TMP_UPDATER}
            mkdir -p ${DIR_TMP_UPDATER}
            mkdir -p ${DIR_TMP_UPDATER}/${REPO_VER}
            curl -L -o ${DIR_TMP}/ungoogled-chromium-${REPO_VER}_tar.xz ${REPO_LINK}
            tar -xf ${DIR_TMP}/ungoogled-chromium-${REPO_VER}_tar.xz -C ${DIR_TMP_UPDATER}/${REPO_VER}
            NEW_VER_DIR=${DIR_TMP_UPDATER}/${REPO_VER}/$(ls -AU ${DIR_TMP_UPDATER}/${REPO_VER} | head -1)
            cp -r $NEW_VER_DIR/* $DIR_INSTALL
            echo $REPO_VER > $FILE_CURRENT_VER
            echo "Updated to: ${REPO_VER}"
            kdialog --title "Ungoogled Chromium Update" \
                --sorry "Restart Ungoogled Chromium is required"
        else
            echo "User reject the update"
        fi    
    else 
        echo "No new version"
    fi
fi 

Alternatives

No response

Additional context

No response

ghost commented 1 year ago

Finally with the help of stackoverflow :-) I've created a pretty "decent" script:

https://github.com/TheNocoder/ungoogled-updater

This may be of interest to: @clickot

rany2 commented 1 year ago

@TheNocoder Bring this up with the packager, not on this repo's issue tracker. The purpose of ungoogled is to not phone home to ANYBODY including the packager, if they want to deviate from that goal it's on them. At any rate, using AppImage has this functionality with something like appimaged; so no need to re implement it yourself; and personally I prefer to use flatpaks as these are truly "portable" and run even without glibc on host machine (they have autoupdate functionality via DE integration)

ghost commented 1 year ago

@TheNocoder Bring this up with the packager, not on this repo's issue tracker. The purpose of ungoogled is to not phone home to ANYBODY including the packager, if they want to deviate from that goal it's on them. At any rate, using AppImage has this functionality with something like appimaged; so no need to re implement it yourself; and personally I prefer to use flatpaks as these are truly "portable" and run even without glibc on host machine (they have autoupdate functionality via DE integration)

Ok, thanks

PF4Public commented 1 year ago

@TheNocoder This might be a good candidate for contrib repo.

PF4Public commented 1 year ago

@TheNocoder Feel free to submit your script into contrib repository if you wish.