forked from jviexonet/media-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
media-docker.sh
120 lines (105 loc) · 3.12 KB
/
media-docker.sh
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
#
# Perform initial setup and configuration of Docker environment for
# full media server goodness.
# shellcheck disable=SC2143
set -euo pipefail
## GLOBALS
get_source() {
local SOURCE
local DIR
SOURCE="${BASH_SOURCE[0]}"
while [[ -h "${SOURCE}" ]]; do
DIR="$( cd -P "$( dirname "${SOURCE}" )" > /dev/null && pwd )"
SOURCE="$(readlink "${SOURCE}")"
[[ ${SOURCE} != /* ]] && SOURCE="${DIR}/${SOURCE}"
done
echo "${SOURCE}"
}
# script info
readonly ARGS=("$@")
readonly ARCH="$(uname -m)"
readonly SOURCENAME="$(get_source)"
readonly CURRENT_UID=$UID
readonly BASEDIR="$( cd -P "$( dirname "$SOURCENAME" )" >/dev/null && pwd )"
readonly SCRIPTDIR="$BASEDIR/.scripts/"
readonly TESTDIR="$BASEDIR/.tests/"
readonly MENUDIR="$BASEDIR/.menus/"
readonly CONFIGDIR="$BASEDIR/.config/"
readonly CONTAINDIR="$BASEDIR/.containers/"
readonly BACKUPDIR="$BASEDIR/.backups/"
readonly LOGFILE="$BASEDIR/.logs/media-docker-$(date +%s).log"
# colors
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly BLUE='\e[34m'
readonly NOCOL='\033[0m'
# logging functions
info() {
echo -e "${BLUE}[INFO] [$(date +'%Y-%m-%dT%H:%M:%S%z')] $*${NOCOL}" \
| tee -a "$LOGFILE" >&2 ;
}
err() {
echo -e "${RED}[ERR] [$(date +'%Y-%m-%dT%H:%M:%S%z')] $*${NOCOL}" \
| tee -a "$LOGFILE" >&2 ;
exit 1
}
success() {
echo -e "${GREEN}[SUCCESS] [$(date +'%Y-%m-%dT%H:%M:%S%z')] $*${NOCOL}" \
| tee -a "$LOGFILE" >&2 ;
}
# script runner
run_sh() {
local DIR="${1:-}"
local FILE="${2:-}"
shift; shift
if [[ -f "${DIR}/${FILE}.sh" ]] ; then
source "${DIR}/${FILE}.sh"
${FILE} "$@";
else
err "${DIR}/${FILE}.sh not found."
fi
}
#/ Usage: sudo media-docker [OPTIONS]
#/ Description: media-docker installation and configuration tool.
#/
#/ To run the GUI installer / configurator, run media-docker without options.
#/
#/ Options:
#/
#/ -p, --prereq <noremove/test>: Install pre-requisites.
#/ -a, --apps: View or edit your .apps file
#/ -e, --env: View or edit your .env file
#/ -c, --compose <up/down/restart/pull/create>: Rebuild your compose environment from selected options
#/ -u, --update: Update media-docker
#/ -P, --prune: Prune the Docker system
#/ -t, --test: Run tests
#/ -h, --help: Display this help message
#/
usage() { grep '^#/' "${SOURCENAME}" | cut -c4- ; exit 0 ; }
finish() {
if [[ $(service --status-all | grep -Fq 'docker') ]] ; then
sudo service docker restart || true
fi
run_sh "$SCRIPTDIR" "self_symlink" || true
run_sh "$SCRIPTDIR" "self_config_delete" || true
sudo rm -f "${TESTDIR}/.apps-test" || true
sudo rm -f "${TESTDIR}/docker-compose-test.yml" || true
}
trap finish EXIT
# main
main() {
# ensure log dir exists
mkdir -p "$(dirname "${LOGFILE}")"
# prereqs for processes
run_sh "$SCRIPTDIR" "arch_is_supported" "$ARCH"
run_sh "$SCRIPTDIR" "root_check"
run_sh "$SCRIPTDIR" "env_create" "$CONFIGDIR" "$BASEDIR"
run_sh "$SCRIPTDIR" "apps_create" "$CONFIGDIR" "$BASEDIR"
run_sh "$SCRIPTDIR" "self_config_store"
# run cli if options are included
run_sh "$MENUDIR" "cli" "${ARGS[@]:-}"
# start menu
run_sh "$MENUDIR" "menu_main" || true
}
main