-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
install.sh
executable file
·138 lines (120 loc) · 3.51 KB
/
install.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env bash
# Copyright (c) 2016-present Sven Greb <[email protected]>
# This source code is licensed under the MIT license found in the license file.
# nounset: Treat unset variables and parameters as an error when performing parameter expansion
# errexit: Exit immediately if any command exits with a non-zero status
set -o nounset -o errexit
_ct_error="\e[0;31m"
_ct_success="\e[0;32m"
_ct_warning="\e[0;33m"
_ct_highlight="\e[0;34m"
_ct_primary="\e[0;36m"
_ct="\e[0;37m"
_ctb_subtle="\e[1;30m"
_ctb_error="\e[1;31m"
_ctb_success="\e[1;32m"
_ctb_warning="\e[1;33m"
_ctb_highlight="\e[1;34m"
_ctb_primary="\e[1;36m"
_ctb="\e[1;37m"
_c_reset="\e[0m"
__help() {
printf "${_ctb}Usage: ${_ct_primary}install.sh ${_ctb_subtle}[OPTIONS]\n"
printf " ${_ctb_highlight}-h${_ct},${_ctb_highlight} --help ${_ct}Help\n"
printf " ${_ctb_highlight}-v${_ct},${_ctb_highlight} --verbose ${_ct}Verbose output\n${_c_reset}"
printf " ${_ctb_highlight}-s${_ct},${_ctb_highlight} --schemefile <SCHEME_FILE> \
${_ct}Use the specified color scheme file\n${_c_reset}"
}
__cleanup() {
trap '' SIGINT SIGTERM
unset -v _ct_error _ct_success _ct_warning _ct_highlight _ct_primary _ct
unset -v _ctb_error _ctb_success _ctb_warning _ctb_highlight _ctb_primary _ctb _c_reset
unset -v NORD_KONSOLE_SCRIPT_OPTS SCHEME_FILE VERBOSE LOCAL_INSTALL NORD_KONSOLE_VERSION
unset -f __help __cleanup __log_error __log_success __log_warning __log_info
unset -f __validate_file __local_install
}
__log_error() {
printf "${_ctb_error}[ERROR] ${_ct}$1${_c_reset}\n"
}
__log_success() {
printf "${_ctb_success}[OK] ${_ct}$1${_c_reset}\n"
}
__log_warning() {
printf "${_ctb_warning}[WARN] ${_ct}$1${_c_reset}\n"
}
__log_info() {
printf "${_ctb}[INFO] ${_ct}$1${_c_reset}\n"
}
__summary_success() {
__log_success "Local installation completed"
__cleanup
exit 0
}
__summary_error() {
__log_error "An error occurred during the installation!"
__log_error "Exit code: $1"
__cleanup
exit 1
}
__local_install() {
__validate_file
if [ ! -d $LOCAL_INSTALL_DIR ]; then
mkdir -p $LOCAL_INSTALL_DIR
if [ $? -eq 0 ]; then
if [ $VERBOSE = true ]; then __log_info "Created local directory $LOCAL_INSTALL_DIR"; fi
else
__log_error "Could not create local directory $LOCAL_INSTALL_DIR"
__summary_error 1
fi
fi
cp -f $SCHEME_FILE $LOCAL_INSTALL_DIR
if [ $? -eq 0 ]; then
if [ $VERBOSE = true ]; then __log_success "Copied color scheme file to $LOCAL_INSTALL_DIR"; fi
__summary_success
else
__log_error "Could not copy color scheme file to $LOCAL_INSTALL_DIR"
__summary_error 1
fi
}
__validate_file() {
if [ ! -f $SCHEME_FILE ]; then
__log_error "Color scheme file not found: $SCHEME_FILE"
__summary_error 1
fi
}
trap "printf '${_ctb_error}User aborted.${_c_reset}\n' && exit 1" SIGINT SIGTERM
NORD_KONSOLE_SCRIPT_OPTS=$(getopt -o vhs: --long verbose,help,schemefile: -n 'install.sh' -- "$@")
SCHEME_FILE=src/nord.colorscheme
VERBOSE=true
NORD_KONSOLE_VERSION=0.1.0
if [ -z "$XDG_DATA_HOME" ]; then
LOCAL_INSTALL_DIR=~/.local/share/konsole
else
LOCAL_INSTALL_DIR="${XDG_DATA_HOME}/konsole"
fi
eval set -- "$NORD_KONSOLE_SCRIPT_OPTS"
while true; do
case "$1" in
-v | --verbose)
VERBOSE=true
shift
;;
-h | --help)
__help
exit 0
break
;;
-s | --schemefile)
SCHEME_FILE="$2"
shift 2
;;
--)
shift
break
;;
*) break ;;
esac
done
__local_install
__cleanup
exit 0