-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduct
119 lines (101 loc) · 3.05 KB
/
duct
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
# vim: set ft=sh syn=bash :
# shellcheck shell=bash
#
# Copyright (C) 2022-2023 Chris 'sh0shin' Frage
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3,
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
set -eu
# initial checks
if [[ ${BASH_VERSINFO[0]} -lt 4 ]]
then
printf "%b\n" "\033[0;31m[ERR] UNSUPPORTED BASH VERSION ${BASH_VERSION}!\033[0m"
printf "%b\n" "\033[0;33m[WRN] MINIMUM SUPPORTED BASH VERSION IS 4.4.0\033[0m"
exit 1
fi
if [[ ! -v BASH || -v ZSH_NAME || -v POSIXLY_CORRECT ]]
then
printf "%b\n" "\033[0;31m[ERR] SORRY! DUCT IS A BASH ONLY FRAMEWORK!\033[0m"
exit 1
fi
if [[ "$0" == "${BASH_SOURCE[0]}" ]]
then
printf "%b\n" "\033[0;31m[ERR] DON'T RUN DUCT DIRECTLY! USE THE 'source'!"
exit 1
fi
# dirs
# shellcheck disable=SC2155
declare -r DUCT_ROOT_DIR="$( test -d "${BASH_SOURCE[0]%/*}" && { cd "${BASH_SOURCE[0]%/*}" || exit; }; echo "$PWD" )"
declare -r DUCT_LOGO_DIR="${DUCT_ROOT_DIR}/logo"
declare -r DUCT_PLUG_DIR="${DUCT_ROOT_DIR}/plug"
# shellcheck disable=SC2034
declare DUCT_PID="$$"
declare DUCT_TMP_DIR="${DUCT_TMP_DIR:-${TMPDIR:-"$HOME/tmp"}}"
declare DUCT_WORK_DIR="${DUCT_WORK_DIR:-$PWD}"
declare DUCT_TERM="${DUCT_TERM:-${TERM:-"dumb"}}"
declare DUCT_TERM_PROGRAM="${DUCT_TERM_PROGRAM:-${TERM_PROGRAM:-"none"}}"
# self
# shellcheck disable=SC2034
if [[ -v BASH_SOURCE[0] ]]
then
declare -r DUCT_SELF_FILE="${BASH_SOURCE[0]:?}"
declare -r DUCT_SELF_NAME="${DUCT_SELF_FILE##*/}"
declare -r DUCT_SELF_PATH="${DUCT_SELF_FILE%/*}"
fi
# script
# shellcheck disable=SC2034
if [[ -v BASH_SOURCE[1] ]]
then
declare -r DUCT_SCRIPT_FILE="${BASH_SOURCE[1]:?}"
declare -r DUCT_SCRIPT_NAME="${DUCT_SCRIPT_FILE##*/}"
declare -r DUCT_SCRIPT_PATH="${DUCT_SCRIPT_FILE%/*}"
fi
# info
# shellcheck disable=SC2034
declare -r DUCT_URL="https://duct.run/"
# shellcheck disable=SC2034,SC2155
declare -r DUCT_VERSION="$( < "${DUCT_ROOT_DIR}/.duct-version" )"
# core plugins
declare -r -a DUCT_PLUG_CORE=(
duct-bash
duct-bugs
duct-msg
duct-core
duct-logo
duct-plug
duct-run
)
for DUCT_ITEM in "${DUCT_PLUG_CORE[@]}"
do
declare -u -n DUCT_PLUG_VAR="__${DUCT_ITEM//-/_}"
# shellcheck disable=SC1090
source "${DUCT_PLUG_DIR}/core/$DUCT_ITEM" && export DUCT_PLUG_VAR=true
if [[ "$DUCT_ITEM" == "duct-core" ]]
then
__duct_env
__duct_conf
fi
done
unset DUCT_ITEM
# init
__duct_init
# install and load optional core plugins
__duct_plug_install core
__duct_plug_load core
# install and load main & vendor plugins
__duct_plug_install main
__duct_plug_load main
__duct_plug_install vendor
__duct_plug_load vendor
# show duct logo and version
__duct_logo