aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2021-11-03 09:16:16 +0000
committermerakor <cem@ckyln.com>2021-11-03 09:16:16 +0000
commitff58b810dcbf96e94571c9e339c08a3cef2d713f (patch)
treebb26bdc31be74fe66d31d19b77469c2820f84765
parentde85a3911d03e818743f83ea118b224f6d765c1b (diff)
downloadcpt-ff58b810dcbf96e94571c9e339c08a3cef2d713f.tar.gz
cpt-lib: define a dedicated cpt configuration directory and change cpt base location
FossilOrigin-Name: aae615102f854abbce81b3a07511b5a29450b673309c834071bc69a7791a226a
-rw-r--r--Makefile1
-rwxr-xr-xconfigure12
-rw-r--r--src/cpt-lib.in15
3 files changed, 22 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 691caf6..108138c 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,7 @@ src/cpt-lib: src/cpt-lib.in
sed -n '/^Copyright/{s,^, ",;s,$$," \\,;p}' LICENSE | \
sed -e '/@LICENSE@/r /dev/stdin' \
-e '/@LICENSE@/d' \
+ -e 's|@SYSCONFDIR@|${SYSCONFDIR}|g' \
-e "s|@VERSION@|${VERSION}|g" \
-e "s|@DOCSTRING@|Call functions from the library|g" src/cpt-lib.in > $@
chmod 755 $@
diff --git a/configure b/configure
index e338b8f..075e183 100755
--- a/configure
+++ b/configure
@@ -28,6 +28,7 @@ usage() {
"Options:" \
" --prefix=dir Set prefix directory" \
" --bindir=dir User executables [PREFIX/bin]" \
+ " --sysconfdir=dir System configuration directory [PREFIX/etc]"
" --datarootdir=dir Data root directory [PREFIX/share]" \
" --mandir=dir Manual pages [DATAROOTDIR/man]" \
" --infodir=dir info documentation [DATAROOTDIR/info]" \
@@ -43,6 +44,7 @@ prefix=/usr/local
# We don't want expansion
# shellcheck disable=2016
{
+sysconfdir='$(PREFIX)/etc'
bindir='$(PREFIX)/bin'
datarootdir='$(PREFIX)/share'
mandir='$(DATAROOTDIR)/man'
@@ -54,8 +56,9 @@ docs=auto
for arg; do
case $arg in
-h|--help) usage ;;
- --prefix=*) prefix=${arg#*=} ;;
- --bindir=*) bindir=${arg#*=} ;;
+ --prefix=*) prefix=${arg#*=} ;;
+ --bindir=*) bindir=${arg#*=} ;;
+ --sysconfdir=*) sysconfdir=${arg#*=} ;;
--mandir=*) mandir=${arg#*=} ;;
--infodir=*) infodir=${arg#*=} ;;
--docdir=*) docdir=${arg#*=} ;;
@@ -68,6 +71,10 @@ for arg; do
esac
done
+# If the prefix is /usr and sysconfdir is not modified, make it /etc
+# shellcheck disable=2016
+[ "$prefix" = /usr ] && [ "$sysconfdir" = '$(PREFIX)/etc' ] && sysconfdir=/etc
+
trap 'rm -f config.mk' EXIT
trap 'rm -f config.mk; exit 1' INT
@@ -78,6 +85,7 @@ out "starting configuration..."
cat <<EOF > config.mk
PREFIX = $prefix
BINDIR = $bindir
+SYSCONFDIR = $sysconfdir
DATAROOTDIR = $datarootdir
MANDIR = $mandir
INFODIR = $infodir
diff --git a/src/cpt-lib.in b/src/cpt-lib.in
index 581d281..8a7983a 100644
--- a/src/cpt-lib.in
+++ b/src/cpt-lib.in
@@ -2013,12 +2013,12 @@ pkg_updates(){
}
pkg_get_base() (
- # Print the packages defined in the /etc/cpt-base file.
+ # Print the packages defined in the CPT base file.
# If an argument is given, it prints a space seperated list instead
# of a list seperated by newlines.
- # cpt-base is an optional file, return with success if it doesn't exist.
- [ -f "$CPT_ROOT/etc/cpt-base" ] || return 0
+ # CPT base is an optional file, return with success if it doesn't exist.
+ [ -f "$cpt_base" ] || return 0
# If there is an argument, change the format to use spaces instead of
# newlines.
@@ -2042,7 +2042,7 @@ pkg_get_base() (
for dep in $deps; do
contains "$*" "$dep" || set -- "$@" "$dep"
done
- done < "$CPT_ROOT/etc/cpt-base"
+ done < "$cpt_base"
# Format variable is intentional.
# shellcheck disable=2059
@@ -2266,6 +2266,13 @@ create_cache() {
# the get go. It will be created as needed by package installation.
sys_db=$CPT_ROOT/$pkg_db
+ # CPT system configuration directory
+ cpt_confdir=${CPT_ROOT}@SYSCONFDIR@/cpt
+
+ # Backwards compatibility for the old cpt-base location
+ cpt_base=$CPT_ROOT/etc/cpt-base
+ [ -f "$cpt_confdir/base" ] && cpt_base=$cpt_confdir/base
+
# Regular expression used in pkg_checksums() and pkg_sources() in order to
# identify VCS and comments
re_vcs_or_com='^(#|(fossil|git|hg)\+)'