mirror of
https://github.com/edu4rdshl/archlinux-pkgrecover.git
synced 2026-07-17 23:24:46 +00:00
Add option to use auto-configure pacman-static in case that pacman is broken using the USE_PACMAN_STATIC=true environment variable
This commit is contained in:
parent
d940a7a7a5
commit
bc17ff70ec
1 changed files with 46 additions and 3 deletions
|
|
@ -1,17 +1,48 @@
|
|||
#!/usr/bin/bash
|
||||
|
||||
USE_PACMAN_STATIC=${USE_PACMAN_STATIC:-"false"}
|
||||
|
||||
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:"
|
||||
echo "https://pkgbuild.com/~morganamilo/pacman-static/x86_64/bin/pacman-static"
|
||||
echo "and then move it to /usr/bin/pacman"
|
||||
|
||||
mv /usr/bin/pacman /usr/bin/pacman.bak
|
||||
curl -Lo /usr/bin/pacman https://pkgbuild.com/~morganamilo/pacman-static/x86_64/bin/pacman-static
|
||||
chmod +x /usr/bin/pacman
|
||||
touch /tmp/pacman-static.installed
|
||||
fi
|
||||
}
|
||||
|
||||
check_dependencies() {
|
||||
if [[ $USE_PACMAN_STATIC == "true" ]]; then
|
||||
install_pacman_static
|
||||
fi
|
||||
|
||||
if ! command -v pacman &>/dev/null; then
|
||||
echo "pacman is not installed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v paclog &>/dev/null; then
|
||||
if [[ "$1" == "paclog" ]] && ! command -v paclog &>/dev/null; then
|
||||
echo "paclog is not installed."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
echo "Cleanup..."
|
||||
|
||||
if [[ -f /usr/bin/pacman.bak ]]; then
|
||||
mv /usr/bin/pacman.bak /usr/bin/pacman
|
||||
fi
|
||||
|
||||
if [[ -f /tmp/pacman-static.installed ]]; then
|
||||
rm /tmp/pacman-static.installed
|
||||
fi
|
||||
}
|
||||
|
||||
check_date_format() {
|
||||
if ! date -d "$1" &>/dev/null; then
|
||||
echo "Please provide a date in the format 'YYYY-MM-DD HH:MM:SS'. See --help for more information."
|
||||
|
|
@ -57,6 +88,8 @@ using_pacman_db() {
|
|||
echo "Reinstalling the following packages:"
|
||||
sudo pacman -S "${matching_packages[@]}" --overwrite='*'
|
||||
fi
|
||||
|
||||
cleanup
|
||||
}
|
||||
|
||||
using_paclog() {
|
||||
|
|
@ -97,10 +130,14 @@ using_paclog() {
|
|||
echo "Reinstalling the following packages:"
|
||||
sudo pacman -S "${matching_packages[@]}" --overwrite='*'
|
||||
fi
|
||||
|
||||
cleanup
|
||||
}
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 [OPTIONS]"
|
||||
echo "Usage: [ENVIRONMENT] $0 [OPTIONS]"
|
||||
echo "ENVIRONMENT:"
|
||||
echo " USE_PACMAN_STATIC=true $0 [OPTIONS] Use pacman-static instead of the default pacman. Useful in cases that pacman is broken. Default is false."
|
||||
echo "Options:"
|
||||
echo " --pacman-db \"<date>\" [--dry-run] Reinstall packages upgraded after the given date using pacman database. Please quote the date in the format 'YYYY-MM-DD HH:MM:SS'"
|
||||
echo " --paclog \"<date>\" [--no-db] [--dry-run] Reinstall packages upgraded after the given date using pacman log. Please quote the date in the format 'YYYY-MM-DD HH:MM:SS'"
|
||||
|
|
@ -111,6 +148,12 @@ if [[ $# -eq 0 ]]; then
|
|||
usage
|
||||
fi
|
||||
|
||||
# Check that we are running as root
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Parse the command line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
|
|
@ -120,7 +163,7 @@ while [[ $# -gt 0 ]]; do
|
|||
exit 0
|
||||
;;
|
||||
--paclog)
|
||||
check_dependencies
|
||||
check_dependencies "paclog"
|
||||
using_paclog "$2" "$3" "$4"
|
||||
exit 0
|
||||
;;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue