-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuberports
200 lines (173 loc) · 5.2 KB
/
uberports
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/ksh
# uberports(8): Simple heap of shell hacks for installing Slackbuilds in the BSD Ports style.
# Copyright (c) 2021-2023 Luiz Antônio Rangel
# "Error proofing"
set -e
progname="${0}"
shell="$(readlink -f /proc/$$/exe)"
LC_ALL='POSIX'
. /usr/etc/ports.conf
. /etc/os-release
unset NAME ID VERSION_ID PRETTY_NAME ANSI_COLOR CPE_NAME \
HOME_URL SUPPORT_URL BUG_REPORT_URL
ports_directory='/usr/ports'
slackware_pkg_directory="$(cd /var/log/packages; pwd -P)"
uberports_version='0.3'
export progname shell ports_directory slackbuilds_mirror \
uberports_version LC_ALL
chdir(){ cd "${@}"; }
fn_syncRepository(){
repo_mirror_basename="${slackbuilds_mirror#*//}"
repo_mirror_basename="${repo_mirror_basename%%/*}"
printf 'Cloning repo via git (%s)\n' "${repo_mirror_basename}"
git clone -v "${slackbuilds_mirror}" -b "${VERSION}" "${ports_directory}"
unset VERSION
}
fn_updateRepository(){
chdir "${ports_directory}"
git pull -v origin "${VERSION}"
chdir -
}
fn_searchPackages(){
slackbuild="$1"
slackbuild_dir="`find "${ports_directory}" -name "${slackbuild}"`"
slackbuild_name="${slackbuild_dir##*/}"
# Return the .info file as plain-text, plus the Slackbuild directory.
echo "slackbuild_dir=${slackbuild_dir}"
cat "${slackbuild_dir}/${slackbuild_name}.info"
}
fn_printPackageInfo(){
queries=(${@})
queries_quant="${#@}"
for (( i=0; i < "${queries_quant}"; i++ )); do
fn_searchPackages "${queries[$i]}" | fn_parseInfoFile
printf '\
Package name: %s
Version: %s
Directory (build scripts): %s
Maintainer: %s
Hotline: %s
Dependencies: %s
' "${PRGNAM}" "${VERSION}" "${slackbuild_dir}" "${MAINTAINER}" \
"${EMAIL}" "${REQUIRES:-None}"
done
}
fn_downloadSource(){
current_directory="$(pwd)"
ports_name="${current_directory##*/}"
. ./"${ports_name}.info" # Source .info file
if [[ "${DOWNLOAD}" =~ (UNSUPPORTED) \
&& "$(uname -m)" == 'x86_64' ]]; then
downloads=(${DOWNLOAD_x86_64})
md5sums=(${MD5SUM_x86_64})
elif [[ "${DOWNLOAD}" =~ (UNSUPPORTED) \
&& "$(uname -m)" != 'x86_64' ]]; then
printf 'This package isn'\''t support in this platform.\n' 1>&2
return 1
else
downloads=(${DOWNLOAD})
md5sums=(${MD5SUM})
fi
download_quant="${#downloads[@]}"
for (( j=0; j < "${download_quant}"; j++ )); do
current_download="${downloads[$j]}"
download_url_basename="${current_download#*//}"
download_url_basename="${download_url_basename%%/*}"
printf 'Downloading %s @ %s (%s).\n' \
"${PRGNAM}" "${VERSION}" "${download_url_basename}"
curl -# -L "${current_download}" -O
done
if echo "$CHECKSUM" | grep -i '^y' &>/dev/null \
&& [ "${download_quant}" == "${#md5sums[@]}" ]; then
for (( m=0; m < ${download_quant}; m++ )); do
download_filename="${downloads[$m]##*/}"
download_checksum="$(md5sum "./${download_filename}")"
download_checksum="${download_checksum%% *}"
if [ "${download_checksum}" != "${md5sums[$m]}" ]; then
printf 'Error: %s checksum don'\''t match.' 1>&2 \
"${download_filename}"
return 1
else
continue
fi
done
fi
}
fn_autoInstall(){
packages=(${@})
packages_quant="${#packages[@]}"
for (( k=0; k < "${packages_quant}"; k++ )); do
current_package="${packages[$k]}"
# Load package information
fn_searchPackages "${current_package}" \
| fn_parseInfoFile
dependencies=(${REQUIRES})
dependencies[${#dependencies[@]}]="${current_package}"
dependencies_quant="${#dependencies[@]}"
if [ -n "$REQUIRES" ]; then
for (( l=0; l < ${dependencies_quant}; l++ )); do
if ls -l "${slackware_pkg_directory}" \
| grep -i "${dependencies[$l]}" &> /dev/null; then
printf '%s is already installed.\n' "${dependencies[$l]}"
else
fn_buildAndInstallPackage "${dependencies[$l]}"
fi
done
elif [[ "$REQUIRES" =~ (README) ]]; then
printf 'This package requires that you read the %s file.' 1>&2\
"${slackbuild_dir}/README"
exit
else
fn_buildAndInstallPackage "${current_package}"
fi
done
}
fn_buildAndInstallPackage(){
# Load package information again
package="$1"
fn_searchPackages "${package}" \
| fn_parseInfoFile
chdir "${slackbuild_dir}"
fn_downloadSource
# "Fork" the SlackBuild script process to a new Korn Shell
# instance.
"$shell" "./${package}.SlackBuild"
installpkg "/tmp/$PRGNAM-$VERSION-*-*.t?z"
}
fn_parseInfoFile(){
# Parses the .info file from Slackbuild by using the '=' character
# as a separator and reading the identifier and value separately,
# then declaring it as a variable in the script using eval.
# The input to this function needs to be passed via a pipe or
# redirection.
while IFS='=' read identifier value; do
eval "$identifier=$value"
done
}
fn_printHelp(){
printf '[USAGE]: %s [-S|-u|[-s|-q <pkg>]|-d|-V|-h]\n' 2>&1 \
"${progname}"
exit 1
}
fn_printVersion(){
printf '
%s
Copyright (c) 2021-2023 Luiz Antônio Rangel
Licenced under the ISC licence
' "${uberports_version}"
}
fn_main(){
OPTPARAMS="Sus:q:dV"
while getopts "${OPTPARAMS}" OPT; do
case "${OPT}" in
"S") fn_syncRepository ;;
"u") fn_updateRepository ;;
"s") fn_autoInstall "${OPTARG}" ;;
"q") fn_printPackageInfo "${OPTARG}" ;;
"d") fn_downloadSource;;
"V") fn_printVersion ;;
"?") fn_printHelp ;;
esac
done
}
fn_main ${@}