# Recovery after failed update or upgrade

Related articles

- Update packages from crontab

Note: This is focused mostly on setting up recovery environment for the home user with low knowledge about computer usage or needs.

If the computer was powered off during an update process it might cause a damage and prevent run of the applications. To avoid this or minimize damage you will need to create a separate recovery environment with pre-made scripts/programs that will help the user to fix the problems on its own or get help by guiding.

### GUI recovery environment

If user did upgrade or update that prevents boot into the desktop environment or applications cannot start but user is able to see the display manager then it is good to make a separate environment for the user that is easy to use to try fix those errors on its own. This will be useful for users that has relatively low knowledge about computer specially about Linux. Install openbox or any other equivalent window manager that they can use with the idesk and create own buttons to the programs or better scripts that are configured to make actions and show warnings and the administrator contact information before starting. To prevent any unwanted user to use the "failsafe" environment or some of the recovery tasks you can add to begin of the script or window manager autostart something like:

    AllowedUser="JolinTsai";
    if [ "$(whoami)" != " ${AllowedUser,,}" ];then zenity --warning --text="You are not the allowed user!
    The allowed user is "$AllowedUser;
    #openbox --exit
    exit 1
    fi

You will need to remove all unnecessary entries from "type of session" list, you can do it by removing or better to moving the *.desktop files which contains information about them to the backup folder and create your own with a custom configuration, to make it simply just copy one of the *.desktop files to a file with the name you want and make changes in the Exec and description parts.

Something like this you can use to remove or move files to backup directory.

    find /usr/share/apps/kdm/sessions/ -maxdepth 1 -type f \
    ! -name kde-plasma.desktop ! -name lxde.desktop ! -name openbox.desktop ! -name xfce4.desktop \
    -exec mv "{}" /usr/share/apps/kdm/sessions/OLD_/ \;

You usually can find them in some of those folders:

    /usr/share/config/kdm/sessions
    /usr/share/apps/kdm/sessions
    /usr/share/xsessions/

You will also need to remove borders from windows to prevent user to close the working window such as xterm if you will use it to show output of commands while they are working. You can do it by using the devilspie.

To get list of the window names for using in the devilspie configuration file you can use the wmctrl utility `wmctrl -l | awk '{print substr($0, index($0,$4))}'` or when you start devilspie you will see all information that is possible to use in the configuration file.

`Window Title: 'name@host:~/.path'; Application Name: 'name@host:~/.path' ; Class: 'XTerm' ; Geometry: 492x350+487+226`

The `window_name` , `application_name` and `window_class` can be used to change the window properties.

Example of the devilspie configuration file that you can use for the preferred application

    .devilspie/DesktopConsole.ds

    (if (is (window_class) "XTerm")
            (begin
    (undecorate)
    (skip_tasklist)
    (above)
    (fullscreen)
    (maximize)
    (unpin)
    (skip_pager)
                )
            )

The XTerm has also a command line to start it in the full screen: `xterm -fullscreen`.

Tip: To run an application in the full screen makes user unable to click on other buttons on the desktop until task is completed.

## Download and fix damaged packages

This article or section is being considered for deletion.

Reason: Recovery script for a very specific problem: the pacman package is "broken beyond repair", but any other package works fine (mainly bash, tar and their dependencies). Just see pacman#Troubleshooting and do it manually, there is no point in automating the recovery for specific problems -- the scripts won't know which problem occurred in the first place. You might want to take a look at http://0pointer.de/blog/projects/stateless.html or Snapper if you need automate fallback solution. (Discuss in Talk:Recovery after failed update or upgrade#)

The factual accuracy of this article or section is disputed.

Reason: The bash script has mistakes in its code. (Discuss in Talk:Recovery after failed update or upgrade#)

If some of the applications got broken then it much easier to download it from the website and extract. By reading logs is possible to determinate which of applications is broken.

Example how to download the pacman package or install it if available in the pacman cache.

    #!/bin/bash
    RepoType=(core extra community)
    Arch="x86_64"
    PacCache="/var/cache/pacman/pkg"
    LogName="down_pkg_log_"
    PathPKG="/tmp"

    PacName="pacman"
    RepoSelect="0"
    #PacName="$1"
    #RepoSelect="$2"

    PacFind="$(ls -1 ${PacCache} --sort=version|awk -v QQ=$Arch -v EE=$PacName '//{if( match($0,EE"-[0-9]") == "1" )ZZ=$1 }
    END{if(index(ZZ,QQ) != 0 )print ZZ}')";

    if [ ! -z "$PacFind" ];then
     tar --exclude-ignore='.MTREE' --exclude-ignore='.PKGINFO'  --exclude-ignore='.INSTALL' -C / -xvf "${PacCache}/${PacFind}"
    else
     wget --content-disposition -m -nd -nH https://www.archlinux.org/packages/${RepoType[RepoSelect]}/${Arch}/${PacName}/download/ -P ${PathPKG} -o "${PathPKG}/${LogName}"
      if [  "$?" != "0" ];then
     xmessage "No Internet connection is available
    and
    cannot find the $PacName file in the pacman cache."
    exit 1
      else
    UnTarPKG="$(awk -v XX=${PacName} -F"$PathPKG" '//{AA=$1;if( $2 ~ "/" && index($2,"[") == "0"  ){KK=$2;
    sub(".","",KK);split(KK,SS,"xz");print SS[1]"xz" }}' /tmp/down_pkg_log_)"
     tar --exclude-ignore='.MTREE' --exclude-ignore='.PKGINFO'  --exclude-ignore='.INSTALL' -C / -xvf "${PathPKG}/${UnTarPKG}"
      fi
    fi

See also: What to do if pacman is broken beyond repair

Note:

- For some programs is enough to remove their configuration files and they will create new on the next start but other need to be restored from a back to preserve made by you configuration for the user.
- To prevent user to delete configuration files by accident you can lock folders from browsing with the `chmod 300 .` or use 733 mask if you will change owner to root or any other admin user that has permission to use sudo command and do `chmod 444 file_name` for the files like .bash_logout , .bash_profile , .bashrc , .xinitrc or any other in the user home folder that has no need to be modified or removed.

This example is a basic template to use when need to make some fixes on the user computer. Just make a tar.gz archive and email it to the user. In this example is used the gksu as GUI for sudo.

    #!/bin/bash

    if [ "$EUID" != "0"  ];then
     if [ ! -z "$(pgrep X)" ];then
      gksudo -u root "xterm -fullscreen -e $0"
     else
      sudo "$0"
     fi

    else

    wget -m -nd -nH your-web-site/update.tar.gz -P /tmp/
    tar xvf /tmp/update.tar.gz -C /
    #................
    # Any other actions to run after extraction
    #................
    sleep 10
    fi

See also: Free web hosting service.

Category:

- System recovery