Compare commits

..

9 commits

Author SHA1 Message Date
Stefan E
bb89239a23
Fix syntax errors and README.md file paths (#2)
* fix syntax errors

* update README.md to use the correct file name

---------

Co-authored-by: sedot42 <git@fry.fastmail.com>
2025-04-24 04:24:11 -05:00
08410b71c0
Update pkgrecover.sh 2024-09-23 00:09:30 -05:00
mrhoomanwastaken
0eec8cceb0
Fix issues involving sudo and root. (#1)
* Fix issues involving sudo and root.

Removed the usage of sudo in the script because it stops pacman from running.
The script will now warn you if you are not root, but it will not stop the script from running to allow usage of dry-run without root privileges.

* Update pkgrecover.sh

Will now check to make sure the important directories are mounted.

* Update pkgrecover.sh

Will now stop people from trying to install packages without root privileges.

* Update pkgrecover.sh

---------

Co-authored-by: Eduard Tolosa <tolosaeduard@gmail.com>
2024-09-23 00:06:17 -05:00
07defa580c
Update README.md 2024-08-18 22:13:46 -05:00
95e2bae897
Update README.md 2024-06-09 14:35:46 -05:00
bc83262ad8
Update README.md 2024-06-09 14:20:35 -05:00
15054cc1d2
Update README.md 2024-06-09 14:19:10 -05:00
0c4d8ca46e
Update README.md 2024-06-09 14:13:41 -05:00
b53d62fb7c
Update README.md 2024-06-09 14:13:15 -05:00
2 changed files with 44 additions and 16 deletions

View file

@ -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

32
pkgrecover.sh Normal file → Executable file
View 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
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 exit 1
fi
fi fi
# Parse the command line arguments # Parse the command line arguments