-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.sh
86 lines (71 loc) · 1.84 KB
/
utils.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
#!/usr/bin/env bash
get_script_install_path () {
echo "${package_bin}/${CONFIG_NAME}"
}
get_package_install_path () {
echo "${package_install_path}/${CONFIG_NAME}"
}
get_package_main () {
echo "$(get_package_install_path)/${CONFIG_MAIN}"
}
required_field () {
if [[ -z $1 ]]; then
echo "Required field ${2} is missing in .${package_name}"
read -rp "${2}=" value
echo "${2}=${value}" >> ".${package_name}"
export "CONFIG_${2}=${value}"
fi
}
recommended_field () {
if [[ -z $1 ]]; then
echo "Recommended field ${2} is missing in .${package_name}"
echo "${3}"
fi
}
validate_config () {
required_field "${CONFIG_NAME:-}" "NAME"
required_field "${CONFIG_MAIN:-}" "MAIN"
required_field "${CONFIG_VERSION:-}" "VERSION"
required_field "${CONFIG_DESCRIPTION:-}" "DESCRIPTION"
recommended_field "${CONFIG_REPOSITORY:-}" "REPOSITORY" " - \"${package_name} update\" will not be available"
}
get_config_file_path () {
echo "$(pwd)/.${package_name}"
}
read_config () {
if [ -f "$(get_config_file_path)" ]; then
while IFS= read -r line; do
export "CONFIG_${line?}"
done < "$(get_config_file_path)"
validate_config
else
echo ".${package_name} file is missing"
exit 1
fi
}
# Not really relative but...
relative_path () {
echo "$(dirname "${BASH_SOURCE[0]}")/${1}"
}
get_repository_name () {
# Get the slug of the url "foo.git"
slug=${1##*/}
# Trim the .git part
repository_name=${slug%.*}
echo "${repository_name}"
}
get_config_field () {
grep "${2}=" < "${package_base}/packages/${1}/.${package_name}" | cut -d= -f2
}
clone_cli_repository () {
( cd "${package_clones_path}" &&
git clone "${1}" ) || exit
}
go_to_cloned_repo () {
cd "${package_clones_path}/${1}" || exit
}
clear_clones () {
if [ -n "${package_clones_path}" ]; then
rm -rf "${package_clones_path:?}"/*
fi
}