-
Notifications
You must be signed in to change notification settings - Fork 1
/
radius_library.sh
75 lines (59 loc) · 1.13 KB
/
radius_library.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
#! /bin/bash
_mysql() {
mysql \
--user=$MYSQL_USER \
--password=$MYSQL_PASSWORD \
$MYSQL_DATABASE \
--execute "$@"
}
_mysql_base() {
mysql \
--user=$MYSQL_USER \
--password=$MYSQL_PASSWORD \
--execute "$@"
}
_mysql_silent() {
mysql \
--user=$MYSQL_USER \
--password=$MYSQL_PASSWORD \
--silent \
--skip-column-names \
$MYSQL_DATABASE \
--execute "$@" 2>/dev/null
}
_password_generator() {
local WEAK="-n 6"
local STRONG="-c -n 10"
local APPEND="$STRONG"
if [ "$1" == "weak" ]; then
local APPEND="$WEAK"
fi
pwgen -1 $APPEND
}
function _label {
local LABEL="$1"
local SUGGESTION="$2"
if [ -n "$SUGGESTION" ]; then
local SUGGESTION_FORMATED=" [$SUGGESTION]"
fi
echo -n "$LABEL$SUGGESTION_FORMATED: "
}
function _prompt {
local NAME="$1"
local LABEL="$2"
local SUGGESTION="$3"
_label "$LABEL" "$SUGGESTION"
read "$NAME"
if [ -z "${!NAME}" ]; then
eval "$NAME='$SUGGESTION'"
fi
export "$NAME"
}
_prompt_yes() {
echo -n "$@ (y|n): "
read YES
if [ "$YES" != "y" ]; then
echo "The process was canceled by the user."
exit 1
fi
}