Updating snaps Script

If it doesn't relate to Debian, but you still want to share it, please do it here

Updating snaps Script

Postby bester69 » 2020-06-07 00:31

Hi,

I made some scripts for manage control snaps updates packages you might find usefull if you use snaps.

update-snaps.sh
- Update one by one snap if there is any update available asking for confirmation..
- filteremove param: exclude packages to ask for update.

Code: Select all
#!/bin/bash
#
fileproc=/tmp/snapcheck.txt
# Filtro paquetes que se quieren conservar versiones anteriores
filteremove="grep -v -e Publisher -e  disabled -e opera -e core* -e gtk* -e gnome-3*"
filteremove="grep -v -e Publisher -e  disabled -e opera"

set -eu
snap list --all | $filteremove   > "$fileproc"

conta=0 && clear
  while read -u 3 line; do
conta=$((conta+1))
#echo "contador es : $conta"
snapname=$(echo "$line" | awk '{print $1}')
version=$(echo "$line" | awk '{print $2}')
revision=$(echo "$line" | awk '{print $3}')
        versnap=$(snap info $snapname|grep latest/stable|grep -v -e "\^" -e tracking | awk '{ print $2 }' )
        revsnap=$(snap info $snapname|grep latest/stable|grep -v -e "\^" -e tracking | awk '{ print $4 }' |tr -d "()")

        if [ $revsnap -gt $revision ]
        then
        echo "Actualiza $snapname:"
        echo  "*ver=$versnap revision=$revsnap"         
        echo  "_ver=$version revision=$revision"
        else
        :
        filtro="$conta"
        filtro+="s/.*//"
         sed -i "$filtro" "$fileproc"
        fi
done 3< "$fileproc"
sed -i '/^$/d' "$fileproc"

conta=0
  while read -u 3 line; do
conta=$((conta+1))
#echo "contador es : $conta"
snapname=$(echo "$line" | awk '{print $1}')

        versnap=$(snap info $snapname|grep latest/stable|grep -v -e "\^" -e tracking | awk '{ print $2 }' )
        revsnap=$(snap info $snapname|grep latest/stable|grep -v -e "\^" -e tracking | awk '{ print $4 }' |tr -d "()")

        read -p "Se Actulizará  $snapname a versión $versnap (y/N)?" choice
            case "$choice" in
                y|Y )
                echo "yes"
                sudo snap refresh $snapname
                    ;;
                n|N ) echo "no";;
            * ) : ;;
        esac         
done 3< "$fileproc"
echo ""
echo "Para Purgar : *****************************"
snap list --all|grep disabled   


Image

purge-snaps.sh
It holds automaticall updates for 60 days until next purge, and then remove/purge all disabled snaps (older retainned versions)
Code: Select all
#!/bin/bash
clear

#Hold 60 días
sudo snap set system refresh.hold="2029-04-23T17:22:54+01:00"
snap refresh --time

# Filtro paquetes que se quieren conservar versiones anteriores
filteremove="grep -v -e opera -e okular"

# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
set -eu

snap list --all | $filteremove | awk '/disabled/{print $1, $3}' |
    while read snapname revision; do
       sudo snap remove "$snapname" --revision="$revision"
    done


tell me if you see something wrong or anything to improve..thanks.
Last edited by bester69 on 2020-06-07 00:49, edited 2 times in total.
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1702
Joined: 2015-04-02 13:15

Re: Updating snaps Script

Postby bester69 » 2020-06-07 00:40

Im not sure if refreshing periodically snap system.hold, can prevent for ever to be updated the packages... im afraid its not possible :? , there must be some type of workaround to avoid any snaps be updated once holded time expire. :?

Code: Select all
#Hold 60 días
sudo snap set system refresh.hold="2029-04-23T17:22:54+01:00"
snap refresh --time
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1702
Joined: 2015-04-02 13:15


Return to Offtopic

Who is online

Users browsing this forum: No registered users and 14 guests

fashionable