From b53d62fb7c16eb63afb241e6c6aec90e4435d556 Mon Sep 17 00:00:00 2001 From: Eduard Tolosa Date: Sun, 9 Jun 2024 14:13:15 -0500 Subject: [PATCH 1/9] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 13a723d..93a85e1 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ The script have two modes of operation: **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. 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: @@ -69,4 +71,4 @@ archlinux-pkgrecover.sh --pacman-db "2024-05-27" # License -This script is licensed under the MIT license. See the [LICENSE](LICENSE) file for more information. \ No newline at end of file +This script is licensed under the MIT license. See the [LICENSE](LICENSE) file for more information. From 0c4d8ca46e7fe960d93e8280c619be83eb702ab3 Mon Sep 17 00:00:00 2001 From: Eduard Tolosa Date: Sun, 9 Jun 2024 14:13:41 -0500 Subject: [PATCH 2/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 93a85e1..4ce9350 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Recover your ArchLinux installation after a mid-upgrade crash # 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 crashes, poer outages, 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. From 15054cc1d236af075275e3dc339a254efedc5372 Mon Sep 17 00:00:00 2001 From: Eduard Tolosa Date: Sun, 9 Jun 2024 14:19:10 -0500 Subject: [PATCH 3/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ce9350..03d5e42 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Recover your ArchLinux installation after a mid-upgrade crash # Purpose -This script is intended to be used when your ArchLinux system crashes, poer outages, 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. +This script is intended to be used when your ArchLinux system crashed, a power outage happened, 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. From bc83262ad81ae6fd412e5118a4c65d2240b1165c Mon Sep 17 00:00:00 2001 From: Eduard Tolosa Date: Sun, 9 Jun 2024 14:20:35 -0500 Subject: [PATCH 4/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 03d5e42..df3d57b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Recover your ArchLinux installation after a mid-upgrade crash # Purpose -This script is intended to be used when your ArchLinux system crashed, a power outage happened, 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. +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. From 95e2bae897c62eb4284cf4eeb23ffb8120c32172 Mon Sep 17 00:00:00 2001 From: Eduard Tolosa Date: Sun, 9 Jun 2024 14:35:46 -0500 Subject: [PATCH 5/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index df3d57b..cc05382 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # archlinux-pkgrecover -Recover your ArchLinux installation after a mid-upgrade crash +Recover your ArchLinux installation after a mid-upgrade crash, power loss, etc. # Purpose 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. From 07defa580c1414444cc965d32618cbe01ff7845c Mon Sep 17 00:00:00 2001 From: Eduard Tolosa Date: Sun, 18 Aug 2024 22:13:46 -0500 Subject: [PATCH 6/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cc05382..e84dddd 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ The script have two modes of operation: # Dependencies - `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 From 0eec8cceb038ec8370258071c845a0dc80a92121 Mon Sep 17 00:00:00 2001 From: mrhoomanwastaken <113311405+mrhoomanwastaken@users.noreply.github.com> Date: Sun, 22 Sep 2024 23:06:17 -0600 Subject: [PATCH 7/9] 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 --- pkgrecover.sh | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/pkgrecover.sh b/pkgrecover.sh index a7f8f5d..b8a711a 100644 --- a/pkgrecover.sh +++ b/pkgrecover.sh @@ -2,7 +2,26 @@ VERSION="1.0.0" 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() { if [[ ! -f /tmp/pacman-static.installed ]]; then echo "Downloading and installing pacman-static. In case that curl fails, you can download the binary from:" @@ -87,7 +106,7 @@ using_pacman_db() { done else echo "Reinstalling the following packages:" - sudo pacman -S "${matching_packages[@]}" --overwrite='*' + pacman -S "${matching_packages[@]}" --overwrite='*' fi cleanup @@ -129,7 +148,7 @@ using_paclog() { done else echo "Reinstalling the following packages:" - sudo pacman -S "${matching_packages[@]}" --overwrite='*' + pacman -S "${matching_packages[@]}" --overwrite='*' fi cleanup @@ -153,8 +172,12 @@ fi # Check that we are running as root if [[ $EUID -ne 0 ]]; then - echo "This script must be run as root." - exit 1 + 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 + fi fi # Parse the command line arguments From 08410b71c0984b467fe6d0bd53bd865bf2e56aa6 Mon Sep 17 00:00:00 2001 From: Eduard Tolosa Date: Mon, 23 Sep 2024 00:09:30 -0500 Subject: [PATCH 8/9] Update pkgrecover.sh --- pkgrecover.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgrecover.sh b/pkgrecover.sh index b8a711a..48a2a48 100644 --- a/pkgrecover.sh +++ b/pkgrecover.sh @@ -22,6 +22,7 @@ directory_check() { exit 1 fi } + install_pacman_static() { if [[ ! -f /tmp/pacman-static.installed ]]; then echo "Downloading and installing pacman-static. In case that curl fails, you can download the binary from:" @@ -49,6 +50,8 @@ check_dependencies() { echo "paclog is not installed. Use the --pacman-db option instead or install the pacutils package." exit 1 fi + + directory_check } cleanup() { From bb89239a2309bb51ea3e3b98e203583623743eb1 Mon Sep 17 00:00:00 2001 From: Stefan E Date: Thu, 24 Apr 2025 11:24:11 +0200 Subject: [PATCH 9/9] 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 --- README.md | 16 ++++++++-------- pkgrecover.sh | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) mode change 100644 => 100755 pkgrecover.sh diff --git a/README.md b/README.md index e84dddd..dfd02ba 100644 --- a/README.md +++ b/README.md @@ -34,10 +34,10 @@ The script have two modes of operation: 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 # 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 -archlinux-pkgrecover.sh --pacman-db/--paclog "2024-05-27" [--no-db] +./pkgrecover.sh --pacman-db/--paclog "2024-05-27" [--no-db] ``` # Examples @@ -45,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: ```bash # 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 -archlinux-pkgrecover.sh --paclog "2024-05-27" +./pkgrecover.sh --paclog "2024-05-27" ``` 2. Using the pacman log file without the pacman database: ```bash # 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 -archlinux-pkgrecover.sh --paclog "2024-05-27" --no-db +./pkgrecover.sh --paclog "2024-05-27" --no-db ``` 3. Using the package database: ```bash # 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 -archlinux-pkgrecover.sh --pacman-db "2024-05-27" +./pkgrecover.sh --pacman-db "2024-05-27" ``` # License diff --git a/pkgrecover.sh b/pkgrecover.sh old mode 100644 new mode 100755 index 48a2a48..997fbde --- a/pkgrecover.sh +++ b/pkgrecover.sh @@ -7,17 +7,17 @@ YELLOW='\033[1;33m' directory_check() { #checks to make sure that all the important directories are mounted properly - if [[ ! -d /proc]]; then + 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 + + 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 + if [[ ! -d /boot ]]; then echo -e "${RED} ERROR: /boot is not mounted. upgrading without /boot mounted can cause damage." exit 1 fi