first try of bash script

This commit is contained in:
2026-03-18 08:15:57 +01:00
parent 5920878e07
commit b345603c3c
2 changed files with 2034 additions and 0 deletions

1985
dpkg.log Normal file

File diff suppressed because it is too large Load Diff

49
reverse_dpkg.sh Executable file
View File

@@ -0,0 +1,49 @@
#!/bin/bash
# Usage: ./reverse_dpkg.sh <dpkg.log_file> [--run]
if [ -z "$1" ]; then
echo "Usage: $0 <dpkg.log_file> [--run]"
exit 1
fi
log_file="$1"
run_flag=false
# Check for --run flag
if [ "$2" == "--run" ]; then
run_flag=true
fi
remove_commands=""
install_commands=""
while IFS= read -r line; do
if [[ "$line" == *"remove"* ]]; then
package=$(echo "$line" | awk '{print $3}')
remove_commands="$remove_commands $package"
elif [[ "$line" == *"install"* ]]; then
package=$(echo "$line" | awk '{print $3}')
install_commands="$install_commands $package"
fi
done < "$log_file"
# Generate commands
apt_commands=""
if [ ! -z "$remove_commands" ]; then
apt_commands+="sudo apt remove $remove_commands\n"
fi
if [ ! -z "$install_commands" ]; then
apt_commands+="sudo apt install $install_commands\n"
fi
apt_commands+="sudo apt --fix-broken install\n"
apt_commands+="sudo apt autoremove\n"
# Output or run commands
if [ "$run_flag" == true ]; then
echo "Executing commands:"
echo "$apt_commands" | bash
else
echo "Generated commands:"
echo "$apt_commands"
fi