Last active 1694074486

An install helper for Debian based distros, that reads user input or a line by line package list in a file

debian_install_helper.sh Raw
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
7function is_package_installed() {
8 dpkg -l | grep -q "^ii $1 "
9}
10
11function install_package() {
12 sudo apt-get install -y "$1" &>> install.log
13}
14
15function 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
27if [ -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
33else
34 echo "Reading input from file..."
35 while IFS= read -r user_input; do
36 try_install "$user_input"
37 done
38fi

Powered by Opengist ⋅ Load: 31ms