-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·111 lines (100 loc) · 2.89 KB
/
install.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
#!/bin/bash
# Exit if no arguments are provided
if [ $# -eq 0 ]; then
exit 0
fi
USE_BUILD_DEP=false
# Parse command-line options
while getopts ":b" opt; do
case $opt in
b)
USE_BUILD_DEP=true
;;
*)
echo "Usage: $0 [-b] [packages...]"
exit 1
;;
esac
done
shift $((OPTIND - 1))
# Detect the OS (we’ll handle build-dep only on Debian-based systems here)
os_name=$(awk -F= '/^ID=/{print $2}' /etc/os-release)
PKG_LIST=()
if $USE_BUILD_DEP && [[ "$os_name" =~ ^(ubuntu|pop|debian)$ ]]; then
# Loop through each package argument
for pkg in "$@"; do
# Run a simulated build-dep to see what would be installed
output=$(sudo apt-get build-dep -s "$pkg" 2>/dev/null)
# Use grep to capture lines that start with "Inst" and extract the package name
deps=$(echo "$output" | grep '^Inst' | awk '{print $2}')
if [ ! -z "$deps" ]; then
for dep in $deps; do
PKG_LIST+=("$dep")
done
fi
done
else
# If not using build-dep, use the provided packages directly.
PKG_LIST=("$@")
fi
# Function to check if a package is installed
is_installed() {
case "$os_name" in
ubuntu|pop|debian)
dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -q "ok installed"
;;
arch)
pacman -Qi "$1" &>/dev/null
;;
fedora)
rpm -q "$1" &>/dev/null
;;
*)
return 1
;;
esac
}
# Now filter out already-installed packages
FINAL_PKGS=()
for pkg in "${PKG_LIST[@]}"; do
if ! is_installed "$pkg"; then
FINAL_PKGS+=("$pkg")
fi
done
# If there are packages to install, install them
if [ ${#FINAL_PKGS[@]} -ne 0 ]; then
case "$os_name" in
ubuntu|pop|debian)
# Use apt-proxy if available; otherwise, fall back to sudo apt
if command -v apt-proxy &>/dev/null; then
APT_COMMAND="apt-proxy"
else
APT_COMMAND="sudo apt"
fi
# Update package lists
until $APT_COMMAND update; do
sleep 10
done
# Install the missing packages; note the use of "--" so package names starting with '-' are safe.
$APT_COMMAND install -y -- "${FINAL_PKGS[@]}"
;;
arch)
if ! command -v yay &>/dev/null; then
sudo pacman -Syu --noconfirm git base-devel
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si
cd ..
rm -rf yay
fi
yay -S --noconfirm "${FINAL_PKGS[@]}"
;;
fedora)
sudo dnf install -y "${FINAL_PKGS[@]}"
;;
*)
echo "Unsupported OS: $os_name"
exit 1
;;
esac
fi