-
Notifications
You must be signed in to change notification settings - Fork 0
/
force-arch-removal.sh
63 lines (51 loc) · 1.71 KB
/
force-arch-removal.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
#!/bin/sh
function check_root() {
echo "Checking root privileges..."
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root" >&2
exit 1
fi
}
check_root
echo "Checking available architectures..."
dpkg-architecture --list | grep "BUILD_ARCH=" | awk -F'=' '{print $2}' > architectures.txt
dpkg --print-foreign-architectures >> architectures.txt
echo "Select the architecture:"
options=()
while read -r line; do
options+=("$line")
done < architectures.txt
select arch in "${options[@]}"; do
if [[ " ${options[*]} " =~ " ${arch} " ]]; then
echo "Selected architecture: $arch"
break
else
echo "Invalid selection! Please choose a number from 1 to ${#options[@]}."
fi
done
echo "Listing installed packages for the specified architecture..."
apt list --installed | grep "$arch" | awk -F'/' '{print $1}' > installed_packages.txt
cat "installed_packages.txt"
while read -r line; do
package_name=$(echo "$line" | cut -d'/' -f1)
if [ -n "$package_name" ]; then
echo "Processing package: $package_name:$arch"
dpkg --purge --force-all "$package_name:$arch"
fi
done < installed_packages.txt
echo "Removing architecture:"
dpkg --remove-architecture "$arch"
echo "Checking for broken packages..."
dpkg --configure -a 2>&1 | grep "^dpkg: error processing package" | awk '{print $5}' | sort -u > broken_packages.txt
while read -r line; do
package_name=$(echo "$line" | cut -d':' -f1)
if [ -n "$package_name" ]; then
echo "Processing package: $package_name"
apt install --reinstall "$package_name"
fi
done < broken_packages.txt
echo "Cleaning up..."
rm installed_packages.txt
rm broken_packages.txt
rm architectures.txt
exit 0