-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreinstall_deps.sh
executable file
·67 lines (52 loc) · 1.6 KB
/
reinstall_deps.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
#!/bin/bash
# Check if an argument is provided
if [ -z "$1" ]; then
echo "Usage: $0 <package> [--auto]"
exit 1
fi
# Check for the --auto argument, which dodges the asking prompt
auto_mode=false
for arg in "$@"; do
if [ "$arg" == "--auto" ]; then
auto_mode=true
break
fi
done
# Run equery g -UMAl on the provided argument
equery_output=$(equery g -UMAl "$1")
# Check the exit status
if [ $? -eq 0 ]; then
echo ""
else
echo "Command failed with exit code $?"
exit 1
fi
# Extract categories from the argument
categories=$(echo "$1" | grep -oE '\b[a-z]+-[a-z]+\b' | sort -u)
# Print the categories
echo $categories
# Get the list of installed packages
installed_packages=$(qlist -Iv)
# Print the equery output, excluding lines with the given category/package-version-revision name, and ensure unique results
dependencies=$(echo "$equery_output" | grep -v "$1" | awk '{$1=""; sub(/^[ \t]+/, ""); sub(/^[0-9]+\] /, ""); print}' | sort | uniq)
# Create a temporary locked file
temp_file=$(mktemp)
# Lock the file
{
flock -x 200
# Check if each dependency is installed and write to the temporary file
for deps in $dependencies; do
if echo "$installed_packages" | grep -q "^$deps$"; then
echo "=$deps" >> "$temp_file"
fi
done
} 200>"$temp_file"
# Output the path to the temporary locked file
echo "Output of command written to $temp_file"
# Emerge the exact packages in the temporary locked file
if [ "$auto_mode" = true ]; then
emerge -v1 $(cat "$temp_file")
else
emerge -va1 $(cat "$temp_file")
fi
# Remove the temporary locked file