Last active 1694074486

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

Millefeuille revised this gist 1694074486. Go to revision

1 file changed, 1 insertion, 1 deletion

debian_install_helper.sh

@@ -9,7 +9,7 @@ function is_package_installed() {
9 9 }
10 10
11 11 function install_package() {
12 - sudo apt-get install -y "$1"
12 + sudo apt-get install -y "$1" &>> install.log
13 13 }
14 14
15 15 function try_install() {

Millefeuille revised this gist 1694074313. Go to revision

1 file changed, 38 insertions

debian_install_helper.sh(file created)

@@ -0,0 +1,38 @@
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"
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
Newer Older

Powered by Opengist ⋅ Load: 7ms