-
Notifications
You must be signed in to change notification settings - Fork 127
/
new_package.sh
executable file
·132 lines (119 loc) · 4.14 KB
/
new_package.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
#!/usr/bin/env bash
ask() {
[ -z ${1+x} ] && exit 1
if [ -z ${2+x} ]; then
read -rp "${1}: " rc
else
rc=$2
fi
echo "$rc"
}
dialog_inputbox() {
dialog \
--colors --no-cancel --title "$1" \
--inputbox "$2" "${3:-15}" "${4:-40}" 3>&1 1>&2 2>&3 3>&-
}
checkpkg() {
if [ -f makefiles/"$1".mk ]; then
echo "$1.mk already exists."
return 1
elif grep -R "^$pkg:" makefiles/*.mk &>/dev/null; then
echo "$1 already exists."
return 1
fi
}
checkbuild() {
if [ ! -f build_misc/templates/"$1".mk ]; then
echo "$1 is not a valid buildsystem"
return 1
fi
}
downloadlink() {
if [ "$(${SED} 's|^.*://||' <<<"${1}" | cut -d'/' -f1)" = "github.com" ]; then
echo -e "\t$\(call GITHUB_ARCHIVE,$(${SED} 's|^.*://||' <<<"${1}" | cut -d'/' -f2),$(${SED} 's|^.*://||' <<<"${1}" | cut -d'/' -f3),$\(${4}_VERSION\),$\(${4}_VERSION\)\)"
else
if echo "${1##*/}" | ${SED} 's/-//g' | ${SED} 's/\.tar.*//g' | ${SED} "s/${2}//g" | grep "${3}" &>/dev/null; then
echo -e "\t$\(call DOWNLOAD_FILES,\$(BUILD_SOURCE),$(${SED} "s/${2}/\$(${4}_VERSION)/g" <<< "$1"))"
else
echo -e "\t$\(call DOWNLOAD_FILE,\$(BUILD_SOURCE)/${3}-\$(${4}_VERSION).tar.${download##*.},$(${SED} "s/${2}/\$(${4}_VERSION)/g" <<< "$1"))"
fi
fi
}
main() {
# shellcheck disable=SC2086
pkg="$(ask "Package Name" $1)"
checkpkg "$pkg" || exit 1
formatpkg="$(${SED} -e 's|-|_|g' -e "s|\(.\)|\u\1|g" <<<"${pkg}")"
while true; do
# shellcheck disable=SC2086
build="$(ask "Build System (type ? to list all build systems)" $2)"
if [ "$build" = "?" ]; then
echo "Available build systems:"
find build_misc/templates -name '*.mk' -not -name 'keyring.mk' -exec basename '{}' .mk \; | $SED 's/^/- /g'
else
if checkbuild "$build"; then
break
elif [ -n "$2" ]; then
exit 1
fi
fi
done
# shellcheck disable=SC2086
ver="$(ask "Package Version" $3)"
# shellcheck disable=SC2086
download="$(ask "Tarball Download Link" $4)"
${SED} -e "s/@pkg@/${pkg}/g" \
-e "s/@PKG@/${formatpkg}/g" \
-e "s/@PKG_VERSION@/${ver}/g" \
-e "s|@download@|$(downloadlink "$download" "$ver" "$pkg" "$formatpkg")|g" \
-e "s|@compression@|${download##*.}|g" \
"build_misc/templates/${build}.mk" > "makefiles/${pkg}.mk"
${SED} -e "s/@pkg@/${pkg}/g" \
-e "s/@PKG@/${formatpkg}/g" \
"build_misc/templates/package.control" > "build_info/${pkg}.control"
}
main_dialog() {
pkg=$(dialog_inputbox "New package" "Package name")
if ! checkpkg "$pkg"; then
dialog --msgbox "$pkg already exists" 15 40
clear
exit 1
fi
formatpkg="$(${SED} -e 's|-|_|g' -e "s|\(.\)|\u\1|g" <<<"${pkg}")"
buildsystems=()
count=1
for i in ./build_misc/templates/*.mk; do
if ! [ "$(basename "$i" .mk)" = "keyring" ]; then
# shellcheck disable=SC2086,SC2207,SC2206
buildsystems+=($count $(basename $i .mk))
count=$((count + 1))
fi
done
build=$(dialog \
--colors --no-cancel --title 'New package' \
--menu 'Build System' 15 40 $count "${buildsystems[@]}" 3>&1 1>&2 2>&3 3>&-)
build=${buildsystems[(( build*2-1 ))]}
ver=$(dialog_inputbox "New package" "Package version")
download=$(dialog_inputbox "New package" "Tarball download link")
${SED} -e "s/@pkg@/${pkg}/g" \
-e "s/@PKG@/${formatpkg}/g" \
-e "s/@PKG_VERSION@/${ver}/g" \
-e "s|@download@|$(downloadlink "$download" "$ver" "$pkg" "$formatpkg")|g" \
-e "s|@compression@|${download##*.}|g" \
"build_misc/templates/${build}.mk" > "makefiles/${pkg}.mk"
${SED} -e "s/@pkg@/${pkg}/g" \
-e "s/@PKG@/${formatpkg}/g" \
"build_misc/templates/package.control" > "build_info/${pkg}.control"
clear
}
if command -v gsed &>/dev/null; then
SED=gsed
else
# shellcheck disable=SC2209
SED=sed
fi
if command -v dialog &>/dev/null && [ -z "$1" ]; then
main_dialog
else
main "$@"
fi