debian_install_helper.sh
Raw
#!/bin/bash
# Usage:
# bash debian_install_helper.sh # to be prompted for packages
# bash debian_install_helper.sh < package_list.txt # to install a newline separated package list
function is_package_installed() {
dpkg -l | grep -q "^ii $1 "
}
function install_package() {
sudo apt-get install -y "$1" &>> install.log
}
function try_install() {
if is_package_installed "$1"; then
echo "Package '$1' is already installed."
else
if install_package "$1"; then
echo "Package '$1' was successfully installed."
else
echo "Error installing package '$1'."
fi
fi
}
if [ -t 0 ]; then
echo "Enter a package name (Ctrl+D to end input):"
while IFS= read -r user_input; do
try_install "$user_input"
echo "Enter a package name (Ctrl+D to end input):"
done
else
echo "Reading input from file..."
while IFS= read -r user_input; do
try_install "$user_input"
done
fi
| 1 | #!/bin/bash |
| 2 | |
| 3 | # Usage: |
| 4 | # bash debian_install_helper.sh # to be prompted for packages |
| 5 | # bash debian_install_helper.sh < package_list.txt # to install a newline separated package list |
| 6 | |
| 7 | function is_package_installed() { |
| 8 | dpkg -l | grep -q "^ii $1 " |
| 9 | } |
| 10 | |
| 11 | function install_package() { |
| 12 | sudo apt-get install -y "$1" &>> install.log |
| 13 | } |
| 14 | |
| 15 | function try_install() { |
| 16 | if is_package_installed "$1"; then |
| 17 | echo "Package '$1' is already installed." |
| 18 | else |
| 19 | if install_package "$1"; then |
| 20 | echo "Package '$1' was successfully installed." |
| 21 | else |
| 22 | echo "Error installing package '$1'." |
| 23 | fi |
| 24 | fi |
| 25 | } |
| 26 | |
| 27 | if [ -t 0 ]; then |
| 28 | echo "Enter a package name (Ctrl+D to end input):" |
| 29 | while IFS= read -r user_input; do |
| 30 | try_install "$user_input" |
| 31 | echo "Enter a package name (Ctrl+D to end input):" |
| 32 | done |
| 33 | else |
| 34 | echo "Reading input from file..." |
| 35 | while IFS= read -r user_input; do |
| 36 | try_install "$user_input" |
| 37 | done |
| 38 | fi |