aboutsummaryrefslogtreecommitdiff
path: root/lib/hydra/misc
blob: f0bf210e2f6b72cb6f85c4217a3e8f5dade01d2c (plain)
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
#!/bin/bash

# Set needed environment variables and do basic checks.
function hydra_set_env {
  export CONFIG="$HOME/.hydra/config"
  export ACTION="$1"

  if [ ! -z "$HYDRA" ]; then
    export PREFERENCES="$HOME/.hydra/$HYDRA"
  fi
}

# Read a parameter from user
function hydra_user_input {
  local input
  param="$1"
  default="$2"
  shift 2
  read -rep "$* (defaults to $default): " input

  if [ -z "$input" ]; then
    export $param=$default
  else
    export $param=$input
  fi
}

# Install a package.
function hydra_install_package {
  if [ -z "$1" ]; then
    return
  fi

  dpkg -s $1 &> /dev/null

  if [ "$?" == "1" ]; then
    DEBIAN_FRONTEND=noninteractive apt-get install $1 -y
  fi
}