We have moved to a new Sailfish OS Forum. Please start new discussions there.
1

zypper remove packages including configs ( apt --purge )

asked 2020-06-29 15:19:12 +0200

speefak gravatar image

I am using Debian Linux and Sailfish OS. SFOS uses packagekit, or zypper. The repository management in zypper is very great compared to apt repository functions. This is a really advantage for using zypper.

BUT : Package management, especially the complete removing of a packet and it' s componets, configurations an created files only works for apt ? I can' t find a zypper analogy for the apt --purge command.

Is there really no function in zypper to do the apt --purge job ?

edit retag flag offensive close delete

1 Answer

Sort by » oldest newest most voted
3

answered 2020-06-29 23:34:42 +0200

zypper does not offer such thing (apt is getter/better,, okay, only different)

rpm -e

should remove package files and
as well not modified config files and put modified ones to xxx.rpmsave

And

#repo purge 
#!/bin/sh
for package in "$@"
do  
  echo "removing config files for $package"  
  for file in $(rpm -q --configfiles $package)  
  do    
    echo "  removing $file"    
    rm -f $file  
  done  
rpm -e $package
done

Put this as executable script (e.g. zypper-purge) and go for it...
(no idea why this is not part of zypper?)

edit flag offensive delete publish link more

Comments

1

you can create a feature request here: https://github.com/openSUSE/zypper/issues

balta ( 2020-06-30 21:55:43 +0200 )edit

Thanks.
And I would like to but this phone and its company with this outdated browser just does not let me! :(

But that is another story.

peterleinchen ( 2020-07-01 00:37:32 +0200 )edit

script does not delete user configs like apt purge does

speefak ( 2020-07-05 17:28:59 +0200 )edit

Then these files are most probably not packaged as config files but created on first start of application (or later) on the fly?
Those files can only be found and deleted manually afaik :(

Have a look at e.g. bash:

rpm -qc bash
peterleinchen ( 2020-07-05 19:23:46 +0200 )edit
2

Script searches files in user dir, post the results and deletes after a countdown. Perhaps i should change the function for deleting agreement instead of automatic countdown ?

#!/bin/bash
# name          : zypper
# desciption    : zypper_purge_addon - add zypper command to remove packages and configfiles.
# autor         : speefak
# licence       : (CC) BY-NC-SA
  VERSION=3.0
#-------------------------------------------------------------------------------------------------------------------------------------------------------
############################################################################################################
#######################################   define global variables   ########################################
############################################################################################################
#-------------------------------------------------------------------------------------------------------------------------------------------------------

RequestDelay=10

#-------------------------------------------------------------------------------------------------------------------------------------------------------

 # grep script processing commands, otherwise execute zypper command directly
 if [[ -z $(grep -w "purge" <<< $@) ]]; then
    eval "zypper $@"
    exit
 else
    # check for root permission
    if [ ! "$(whoami)" = "root" ]; then 
        printf "Are You Root ?\n"
        exit 1
    fi

    for Package in $(echo $@ | sed 's/.*purge//') ; do

        # Check for existing installation and config files
        PackageUserConfigurationFiles=$(find -L /home/nemo  | grep -w "$Package")
        PackageSystemConfigurationFiles=$(rpm -q --configfiles $Package) 
        if [[ ! $? == 0 ]]; then
            printf "$Package is not installed\n"
            PackageSystemConfigurationFiles=    
        else
            # remove package
            printf "removing $Package ... "
            ErrorDeinstall=$(rpm -e $Package)
            if [[ ! $? == 0 ]]; then
                printf "deinstallation error : $ErrorDeinstall."
                printf "skip further package proccessing\n"
                continue
            else
                printf "done \n"
            fi
        fi

        # remove user configuration files
        if [[ -n $PackageUserConfigurationFiles ]]; then
            printf "removing $Package ... user configuration files found:\n"
            printf "$PackageUserConfigurationFiles\n"
            tput civis 
            for i in $(seq 1 $RequestDelay) ;do
                read -t1 -n1 -s -p "removing $Package ... delete files ? ( press any key to abort ) " Request2 
                    if   [[ -n "$Request2" ]] ;then
                        DeleteUserConfigs=false
                        break                   
                    fi
                    DeleteUserConfigs=true
                    printf '%2s\r' $(echo $(($RequestDelay-$i)))
            done
            printf '%50s\r'
            tput cnorm

            # remove system configuration files
            if [[ $DeleteUserConfigs == false ]]; then
                printf '%-90s\n' "removing $Package ... keep user configuration files" 
            else
                rm -rf $PackageUserConfigurationFiles
                printf '%-90s\n' "removing $Package ... user configuration files deleted" 
            fi
        fi
    done
 fi

#-------------------------------------------------------------------------------------------------------------------------------------------------------

exit 0
speefak ( 2020-07-05 20:39:32 +0200 )edit
Login/Signup to Answer

Question tools

Follow
3 followers

Stats

Asked: 2020-06-29 15:19:12 +0200

Seen: 5,960 times

Last updated: Jul 06 '20