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>
This commit is contained in:
mrhoomanwastaken 2024-09-22 23:06:17 -06:00 committed by GitHub
parent 07defa580c
commit 0eec8cceb0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,7 +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
echo "Downloading and installing pacman-static. In case that curl fails, you can download the binary from:" 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 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 +148,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,9 +172,13 @@ 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
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do