-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper.sh
executable file
·69 lines (59 loc) · 1.72 KB
/
helper.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
#!/bin/bash
DOTFILE_PATH="$HOME/.dotfiles"
TEMPLATES_PATH="$HOME/.dotfiles/templates"
PACKAGES_PATH="$HOME/.dotfiles/packages"
msg() {
printf '%b\n' "$1" >&2
}
msg_info() {
msg "\33[34m[*]\33[0m ${1}"
}
msg_debug() {
msg "\33[36m[d]\33[0m ${1}"
}
msg_ok() {
msg "\33[32m[+]\33[0m ${1}"
}
msg_error() {
msg "\33[31m[-]\33[0m ${1}: ${2}"
}
echo "1 - New package"
echo "2 - New package (with configs)"
read -p "Action: " -n 1 action
echo
read -p "Package name: " pname
echo
read -p "Only one distro? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]];then
read -p "Distro name: " distro
fi
echo
if [[ ! -z $distro ]]; then
distro="_${distro}"
else
distro=""
fi
if [[ "$action" == "1" ]];then
msg_debug "New package"
sed "s/program/${pname}${distro}/g" "${TEMPLATES_PATH}/install.sh" > "${PACKAGES_PATH}/${pname}.sh"
if [[ $? -eq 0 ]]; then
msg_ok "Created template configuration for '${pname}' in '${PACKAGES_PATH}/${pname}.sh'"
else
msg_error "Unable to create the '${PACKAGES_PATH}/${pname}.sh' template"
fi
elif [[ "$action" == "2" ]];then
msg_debug "New package (with configs)"
mkdir -p "${DOTFILE_PATH}/${pname}"
if [[ $? -eq 0 ]]; then
msg_ok "Created folder ${DOTFILE_PATH}/${pname}"
sed "s/program/${pname}${distro}/g" "${TEMPLATES_PATH}/install.sh" > "${DOTFILE_PATH}/${pname}/install.sh"
if [[ $? -eq 0 ]]; then
msg_ok "Created template configuration for '${pname}' in '${DOTFILE_PATH}/${pname}/install.sh'"
else
msg_error "Unable to create the '${DOTFILE_PATH}/${pname}/install.sh' template"
fi
else
msg_error "Folder '${DOTFILE_PATH}/${pname}', not created (already exists?)"
fi
fi