mirror of
https://github.com/edu4rdshl/archlinux-pkgrecover.git
synced 2026-07-18 07:34:45 +00:00
Compare commits
9 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb89239a23 | ||
| 08410b71c0 | |||
|
|
0eec8cceb0 | ||
| 07defa580c | |||
| 95e2bae897 | |||
| bc83262ad8 | |||
| 15054cc1d2 | |||
| 0c4d8ca46e | |||
| b53d62fb7c |
2 changed files with 44 additions and 16 deletions
24
README.md
24
README.md
|
|
@ -1,8 +1,8 @@
|
||||||
# archlinux-pkgrecover
|
# archlinux-pkgrecover
|
||||||
Recover your ArchLinux installation after a mid-upgrade crash
|
Recover your ArchLinux installation after a mid-upgrade crash, power loss, etc.
|
||||||
|
|
||||||
# Purpose
|
# Purpose
|
||||||
This script is intended to be used when your ArchLinux system crashes during a system upgrade, leaving your system in an inconsistent state. The script will attempt to recover your system by reinstalling all packages that were installed before the crash. Here, before the crash means the date that **you** specify.
|
This script is intended to be used when your ArchLinux system crashed, a power outage happens, etc, during a system upgrade, leaving your system in an inconsistent state. The script will attempt to recover your system by reinstalling all packages that were installed before the crash. Here, before the crash means the date that **you** specify.
|
||||||
|
|
||||||
**Note:** You don't need a very specific date, just a date that is close to the date of the crash. The script will then look for all packages that were installed after that date and will reinstall them.
|
**Note:** You don't need a very specific date, just a date that is close to the date of the crash. The script will then look for all packages that were installed after that date and will reinstall them.
|
||||||
|
|
||||||
|
|
@ -21,21 +21,23 @@ The script have two modes of operation:
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
- `pacutils` (optional): Required if you want to use the `--paclog` option. You can install it from the official repositories.
|
- `pacutils` (optional): Required if you want to use the `--paclog` option. You can install it from the official repositories.
|
||||||
- `pacman` (required): Required for the script to work. It's installed by default on ArchLinux systems. In case that your pacman got corrupted, you can use the [pacman-static](https://aur.archlinux.org/packages/pacman-static/) package from the AUR.
|
- `pacman` (required): Required for the script to work. It's installed by default on ArchLinux systems. In case that your pacman got corrupted, you can use the [pacman-static](https://aur.archlinux.org/packages/pacman-static/) package from the AUR by installing it manually or simply setting the `USE_PACMAN_STATIC=true` environment variable when launching the script.
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
**Important:** Quote the date argument if it contains spaces or special characters.
|
**Important:** Quote the date argument if it contains spaces or special characters.
|
||||||
|
|
||||||
|
**Tip:** If your local pacman installation is broken, use the `USE_PACMAN_STATIC=true` environment variable when launching the script.
|
||||||
|
|
||||||
1. Get a shell on your system. You can use a live CD + a chroot environment (recommended) or simply a shell on the crashed system.
|
1. Get a shell on your system. You can use a live CD + a chroot environment (recommended) or simply a shell on the crashed system.
|
||||||
2. Download the script.
|
2. Download the script.
|
||||||
3. Run the script with the date of the last successful upgrade as an argument. For example, if the last successful upgrade was on the 27th of May 2024, you would run the script as follows:
|
3. Run the script with the date of the last successful upgrade as an argument. For example, if the last successful upgrade was on the 27th of May 2024, you would run the script as follows:
|
||||||
```bash
|
```bash
|
||||||
# Check first what packages will be reinstalled using the --dry-run option
|
# Check first what packages will be reinstalled using the --dry-run option
|
||||||
archlinux-pkgrecover.sh --pacman-db/--paclog "2024-05-27" [--no-db] --dry-run
|
./pkgrecover.sh --pacman-db/--paclog "2024-05-27" [--no-db] --dry-run
|
||||||
|
|
||||||
# If you are happy with the list of packages that will be reinstalled
|
# If you are happy with the list of packages that will be reinstalled
|
||||||
archlinux-pkgrecover.sh --pacman-db/--paclog "2024-05-27" [--no-db]
|
./pkgrecover.sh --pacman-db/--paclog "2024-05-27" [--no-db]
|
||||||
```
|
```
|
||||||
|
|
||||||
# Examples
|
# Examples
|
||||||
|
|
@ -43,28 +45,28 @@ archlinux-pkgrecover.sh --pacman-db/--paclog "2024-05-27" [--no-db]
|
||||||
1. Using the pacman log file among with the pacman database:
|
1. Using the pacman log file among with the pacman database:
|
||||||
```bash
|
```bash
|
||||||
# Check first what packages will be reinstalled using the --dry-run option
|
# Check first what packages will be reinstalled using the --dry-run option
|
||||||
archlinux-pkgrecover.sh --paclog "2024-05-27" --dry-run
|
./pkgrecover.sh --paclog "2024-05-27" --dry-run
|
||||||
|
|
||||||
# If you are happy with the list of packages that will be reinstalled
|
# If you are happy with the list of packages that will be reinstalled
|
||||||
archlinux-pkgrecover.sh --paclog "2024-05-27"
|
./pkgrecover.sh --paclog "2024-05-27"
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Using the pacman log file without the pacman database:
|
2. Using the pacman log file without the pacman database:
|
||||||
```bash
|
```bash
|
||||||
# Check first what packages will be reinstalled using the --dry-run option
|
# Check first what packages will be reinstalled using the --dry-run option
|
||||||
archlinux-pkgrecover.sh --paclog "2024-05-27" --no-db --dry-run
|
./pkgrecover.sh --paclog "2024-05-27" --no-db --dry-run
|
||||||
|
|
||||||
# If you are happy with the list of packages that will be reinstalled
|
# If you are happy with the list of packages that will be reinstalled
|
||||||
archlinux-pkgrecover.sh --paclog "2024-05-27" --no-db
|
./pkgrecover.sh --paclog "2024-05-27" --no-db
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Using the package database:
|
3. Using the package database:
|
||||||
```bash
|
```bash
|
||||||
# Check first what packages will be reinstalled using the --dry-run option
|
# Check first what packages will be reinstalled using the --dry-run option
|
||||||
archlinux-pkgrecover.sh --pacman-db "2024-05-27" --dry-run
|
./pkgrecover.sh --pacman-db "2024-05-27" --dry-run
|
||||||
|
|
||||||
# If you are happy with the list of packages that will be reinstalled
|
# If you are happy with the list of packages that will be reinstalled
|
||||||
archlinux-pkgrecover.sh --pacman-db "2024-05-27"
|
./pkgrecover.sh --pacman-db "2024-05-27"
|
||||||
```
|
```
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
|
||||||
34
pkgrecover.sh
Normal file → Executable file
34
pkgrecover.sh
Normal file → Executable file
|
|
@ -2,6 +2,26 @@
|
||||||
|
|
||||||
VERSION="1.0.0"
|
VERSION="1.0.0"
|
||||||
USE_PACMAN_STATIC=${USE_PACMAN_STATIC:-"false"}
|
USE_PACMAN_STATIC=${USE_PACMAN_STATIC:-"false"}
|
||||||
|
RED='\033[0;31m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
|
||||||
|
directory_check() {
|
||||||
|
#checks to make sure that all the important directories are mounted properly
|
||||||
|
if [[ ! -d /proc ]]; then
|
||||||
|
echo -e "${RED} ERROR: /proc is not mounted. upgrading without /proc mounted can cause damage."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -d /sys ]]; then
|
||||||
|
echo -e "${RED} ERROR: /sys is not mounted. upgrading without /sys mounted can cause damage."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -d /boot ]]; then
|
||||||
|
echo -e "${RED} ERROR: /boot is not mounted. upgrading without /boot mounted can cause damage."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
install_pacman_static() {
|
install_pacman_static() {
|
||||||
if [[ ! -f /tmp/pacman-static.installed ]]; then
|
if [[ ! -f /tmp/pacman-static.installed ]]; then
|
||||||
|
|
@ -30,6 +50,8 @@ check_dependencies() {
|
||||||
echo "paclog is not installed. Use the --pacman-db option instead or install the pacutils package."
|
echo "paclog is not installed. Use the --pacman-db option instead or install the pacutils package."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
directory_check
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
|
|
@ -87,7 +109,7 @@ using_pacman_db() {
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo "Reinstalling the following packages:"
|
echo "Reinstalling the following packages:"
|
||||||
sudo pacman -S "${matching_packages[@]}" --overwrite='*'
|
pacman -S "${matching_packages[@]}" --overwrite='*'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
|
@ -129,7 +151,7 @@ using_paclog() {
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo "Reinstalling the following packages:"
|
echo "Reinstalling the following packages:"
|
||||||
sudo pacman -S "${matching_packages[@]}" --overwrite='*'
|
pacman -S "${matching_packages[@]}" --overwrite='*'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
|
@ -153,8 +175,12 @@ fi
|
||||||
|
|
||||||
# Check that we are running as root
|
# Check that we are running as root
|
||||||
if [[ $EUID -ne 0 ]]; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
echo "This script must be run as root."
|
if [[ $3 == "--dry-run" ]] || [[ $2 == "--dry-run" ]]; then
|
||||||
exit 1
|
echo -e "${YELLOW}WARNING: This script must be run as root in order to install pacman packages. Proceeding because it's a dry-run operation."
|
||||||
|
else
|
||||||
|
echo -e "${RED}ERROR: This script must be run as root in order to install pacman packages."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Parse the command line arguments
|
# Parse the command line arguments
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue