-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.sh
More file actions
105 lines (90 loc) · 2 KB
/
helper.sh
File metadata and controls
105 lines (90 loc) · 2 KB
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
#!/bin/bash
# Variables
kb_layout="no-latin1"
ping_test="google.com"
mirror_countries="country=NO&country=NL"
mirrorlist="/etc/pacman.d/mirrorlist"
zoneinfo="Europe/Oslo"
# Colors
# Grey
LG='\033[0;37m'
# Purple
P='\033[0;35m'
# Green
G='\033[0;32m'
# None
X='\033[0m'
# Variables
spaces=" "
prefix () {
now=$(date +%H:%M:%S)
prefix="${P}[Installer]${X}${LG}[${now}]${X} "
echo -e "$prefix"
}
# Lists options numbered 1 to n
# Usage: options opts
# opts - String of newline separated options
options () {
n=1
echo "$1" | while read line ; do
echo "${spaces}$n. $line" | tee /dev/fd/3
n=$((n+1))
done
}
# Returns selected option value
# Usage: chooser opts label
# opts - String of newline separated options
# label - Category
# full - Return the full value instead of first word
chooser () {
read -p "${spaces}$2 number (default=1): " val 2>&3
if [[ ! $val ]]; then
val=1
fi
res=$(echo "$1" | awk "NR==$val")
if [[ $3 ]]; then
echo "$res"
else
echo "$res" | cut -d " " -f1
fi
}
# Yes/no promt
# Usage: yesno promt
# promt - Question to answer
yesno () {
read -p "$(prefix)$1 (y/n default=n): " answer 2>&3
echo "$answer"
}
# Input promt
# Usage: input promt
# promt - Promt message
# hidden - Hide input
input () {
if [[ $2 == "hidden" ]] ; then
read -s -p "$(prefix)$1: " var 2>&3
else
read -p "$(prefix)$1: " var 2>&3
fi
echo "$var"
}
# Pauses execution
# Usage: pause message
# message - Pause message
pause () {
read -p "$(prefix)$1" 2>&3
}
# Logs a message to the console
# Usage: log message
# message - Message to be printed
log () {
message="$1"
n=1
echo -en "$(prefix)" | tee /dev/fd/3
echo -e "$message" | while read -r line ; do
if [[ $n > 1 ]] ; then
echo -en "$spaces" | tee /dev/fd/3
fi
echo -e "${line}" | tee /dev/fd/3
n=$((n+1))
done
}