-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomnipkgBAD.sh
159 lines (141 loc) · 4.11 KB
/
omnipkgBAD.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
set -e # Exit on error
# Constants
LOG_FILE="/var/log/package_manager.log"
# Functions
check_root() {
if [[ "$EUID" -ne 0 ]]; then
echo "Please run as root or with sudo."
exit 1
fi
}
log() {
local level="$1"
local message="$2"
local timestamp
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "$timestamp - [$level] - $message" | tee -a "$LOG_FILE"
}
check_internet() {
log "INFO" "Checking internet connectivity..."
if ! ping -q -c 1 -W 1 8.8.8.8 &> /dev/null; then
log "ERROR" "No internet connection detected. Please check your network and try again."
exit 1
fi
log "INFO" "Internet connection is active."
}
install_aur_helper() {
local helper="$1"
if command -v "$helper" &> /dev/null; then
log "INFO" "$helper is already installed."
return 0
fi
log "INFO" "$helper not found. Attempting to install using pacman..."
case "$helper" in
yay)
pacman -S --noconfirm --needed yay || log "ERROR" "Failed to install $helper. Install it manually."
;;
paru)
pacman -S --noconfirm --needed paru || log "ERROR" "Failed to install $helper. Install it manually."
;;
trizen)
pacman -S --noconfirm --needed trizen || log "ERROR" "Failed to install $helper. Install it manually."
;;
pikaur)
pacman -S --noconfirm --needed pikaur || log "ERROR" "Failed to install $helper. Install it manually."
;;
*)
log "ERROR" "Unknown AUR helper: $helper. Cannot install."
;;
esac
}
check_and_install_aur_helpers() {
local helpers=("yay" "paru" "trizen" "pikaur")
for helper in "${helpers[@]}"; do
install_aur_helper "$helper"
done
}
# Package manager commands
declare -A PM_COMMANDS=(
["pacman_list"]="pacman -Qq"
["yay_list"]="yay -Qq"
["paru_list"]="paru -Qq"
["trizen_list"]="trizen -Qq"
["pikaur_list"]="pikaur -Qq"
)
declare -A INSTALL_COMMANDS=(
["pacman"]="pacman -S --noconfirm"
["yay"]="yay -S --noconfirm"
["paru"]="paru -S --noconfirm"
["trizen"]="trizen -S --noconfirm"
["pikaur"]="pikaur -S --noconfirm"
)
detect_managers() {
local available_managers=()
for manager in "${!PM_COMMANDS[@]}"; do
if command -v "${manager/_list/}" &> /dev/null; then
available_managers+=("${manager/_list/}")
fi
done
echo "${available_managers[@]}"
}
install_package() {
local package="$1"
log "INFO" "Installing $package..."
for manager in $(detect_managers); do
if run_command "${INSTALL_COMMANDS["${manager}"]} $package"; then
log "INFO" "$package installed with $manager."
return
fi
done
log "ERROR" "Failed to install $package with any package manager."
exit 1
}
update_packages() {
log "INFO" "Updating all packages..."
for manager in $(detect_managers); do
case "$manager" in
pacman) run_command "pacman -Syu --noconfirm" ;;
yay) run_command "yay -Syu --noconfirm" ;;
paru) run_command "paru -Syu --noconfirm" ;;
trizen) run_command "trizen -Syu --noconfirm" ;;
pikaur) run_command "pikaur -Syu --noconfirm" ;;
esac
done
log "INFO" "All packages updated."
}
show_help() {
echo "Usage: $0 {install|update|help} [args...]"
echo
echo "Commands:"
echo " install <packages...> Install specified packages"
echo " update Update all installed packages"
echo " help Show this help message"
}
run_command() {
local command="$1"
if eval "$command"; then
log "INFO" "Successfully executed: $command"
else
log "ERROR" "Error executing: $command"
exit 1
fi
}
# Main script logic
check_root
check_internet
check_and_install_aur_helpers
case "$1" in
install)
shift
for package in "$@"; do
install_package "$package"
done
;;
update)
update_packages
;;
help|*)
show_help
;;
esac