[pacman-dev] [PATCH 1/4] Use sysconfdir instead of hardcoded /etc

Nezmer git at nezmer.info
Mon Oct 11 15:16:46 EDT 2010


 "/etc" was hardcoded in some scripts and manpages. Change this to
 respect sysconfdir

Signed-off-by: Nezmer <git at nezmer.info>
---
 contrib/Makefile.am       |   10 ++++++++++
 contrib/bacman            |   12 ++++++------
 contrib/pacscripts        |    2 +-
 contrib/pactree           |    6 +++---
 contrib/wget-xdelta.sh    |    4 ++--
 contrib/zsh_completion    |    6 +++---
 doc/Makefile.am           |    8 ++++++++
 doc/makepkg.8.txt         |    2 +-
 doc/pacman.conf.5.txt     |    4 ++--
 scripts/rankmirrors.sh.in |    2 +-
 10 files changed, 37 insertions(+), 19 deletions(-)

diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index c6243b1..cb2ffc7 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -12,4 +12,14 @@ EXTRA_DIST = \
 	zsh_completion \
 	README
 
+edit = sed -e 's|@sysconfdir[@]|$(sysconfdir)|g'
+
+# Use sysconfdir
+$(EXTRA_DIST): Makefile
+	cp -a $@ $@.tmp # To reserve permissions in tmp files
+	$(edit) $@ >$@.tmp || true
+	mv $@.tmp $@
+
+all-am: $(EXTRA_DIST)
+
 # vim:set ts=2 sw=2 noet:
diff --git a/contrib/bacman b/contrib/bacman
index 6dd7839..dfb0ad9 100755
--- a/contrib/bacman
+++ b/contrib/bacman
@@ -67,20 +67,20 @@ fi
 #
 # Setting environmental variables
 #
-if [ ! -r /etc/pacman.conf ]; then
-    echo "ERROR: unable to read /etc/pacman.conf"
+if [ ! -r @sysconfdir@/pacman.conf ]; then
+    echo "ERROR: unable to read @sysconfdir@/pacman.conf"
     exit 1
 fi
 
-eval $(awk '/DBPath/ {print $1$2$3}' /etc/pacman.conf)
+eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
 pac_db="${DBPath:-/var/lib/pacman/}/local"
 
-if [ ! -r /etc/makepkg.conf ]; then
-    echo "ERROR: unable to read /etc/makepkg.conf"
+if [ ! -r @sysconfdir@/makepkg.conf ]; then
+    echo "ERROR: unable to read @sysconfdir@/makepkg.conf"
     exit 1
 fi
 
-source "/etc/makepkg.conf"
+source "@sysconfdir@/makepkg.conf"
 if [ -r ~/.makepkg.conf ]; then
     source ~/.makepkg.conf
 fi
diff --git a/contrib/pacscripts b/contrib/pacscripts
index 101fb15..b4fdf32 100755
--- a/contrib/pacscripts
+++ b/contrib/pacscripts
@@ -27,7 +27,7 @@ set -o errexit
 progname=$(basename $0)
 progver="0.4"
 
-conf="/etc/pacman.conf"
+conf="@sysconfdir@/pacman.conf"
 
 if [ ! -r "$conf" ]; then
 	echo "ERROR: unable to read $conf"
diff --git a/contrib/pactree b/contrib/pactree
index 6051724..ed55a61 100755
--- a/contrib/pactree
+++ b/contrib/pactree
@@ -272,11 +272,11 @@ if [ $graphviz -eq 1 ]; then
 	fi
 fi
 
-if [ ! -r /etc/pacman.conf ]; then
-	echo "ERROR: unable to read /etc/pacman.conf"
+if [ ! -r @sysconfdir@/pacman.conf ]; then
+	echo "ERROR: unable to read @sysconfdir@/pacman.conf"
 	exit 1
 else
-	eval $(awk '/DBPath/ {print $1$2$3}' /etc/pacman.conf)
+	eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
 fi
 
 pac_db="${DBPath:-/var/lib/pacman}/local"
diff --git a/contrib/wget-xdelta.sh b/contrib/wget-xdelta.sh
index 4656f4d..03b3b6e 100755
--- a/contrib/wget-xdelta.sh
+++ b/contrib/wget-xdelta.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 
-if [ -r "/etc/makepkg.conf" ]; then
-	source /etc/makepkg.conf
+if [ -r "@sysconfdir@/makepkg.conf" ]; then
+	source @sysconfdir@/makepkg.conf
 else
 	echo "wget-xdelta: Unable to find makepkg.conf"
 	exit 1
diff --git a/contrib/zsh_completion b/contrib/zsh_completion
index f69fe63..9b67881 100644
--- a/contrib/zsh_completion
+++ b/contrib/zsh_completion
@@ -222,14 +222,14 @@ _pacman_completions_all_groups() {
 _pacman_completions_all_packages() {
 	local -a cmd packages repositories packages_long
 
-	repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
+	repositories=(${(o)${${${(M)${(f)"$(<@sysconfdir@/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
 	typeset -U repositories
 	packages_long=(/var/lib/pacman/sync/${^repositories}/*(/))
 	packages=(${(o)${${packages_long/\/var\/lib\/pacman\/sync\//}#*/}%-*-*} )
 	typeset -U packages
 	_wanted packages expl "packages" compadd - "${(@)packages}"
 	if [[ $PREFIX != */* ]] ; then
-		repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
+		repositories=(${(o)${${${(M)${(f)"$(<@sysconfdir@/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
 		typeset -U repositories
 		_wanted repo_packages expl "repository/package" compadd -S "/" $repositories
 	else
@@ -261,7 +261,7 @@ _pacman_completions_installed_packages() {
 # provides completions for repository names
 _pacman_completions_repositories() {
 	local -a cmd repositories
-	repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
+	repositories=(${(o)${${${(M)${(f)"$(<@sysconfdir@/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
 	# Uniq the array
 	typeset -U repositories
 	compadd "$@" -a repositories
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 2e656f6..91a7695 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -66,6 +66,8 @@ else
 REAL_PACKAGE_VERSION = $(PACKAGE_VERSION)
 endif
 
+edit = sed -e 's|@sysconfdir[@]|$(sysconfdir)|g'
+
 man_MANS =
 dist_man_MANS = $(ASCIIDOC_MANS) repo-remove.8
 
@@ -124,6 +126,12 @@ $(HTML_OTHER): asciidoc.conf
 %.5.html: ASCIIDOC_OPTS += -d manpage
 %.3.html: ASCIIDOC_OPTS += -d manpage
 
+# Use sysconfdir
+%.txt: Makefile
+	cp -a $@ $@.tmp # To reserve permissions in tmp files
+	$(edit) $@ >$@.tmp || true
+	mv $@.tmp $@
+
 # Dependency rules
 pacman.8 pacman.8.html: pacman.8.txt
 makepkg.8 makepkg.8.html: makepkg.8.txt
diff --git a/doc/makepkg.8.txt b/doc/makepkg.8.txt
index a2fdb3f..4251f38 100644
--- a/doc/makepkg.8.txt
+++ b/doc/makepkg.8.txt
@@ -53,7 +53,7 @@ Options
 	in linkman:makepkg.conf[5].
 
 *--config* <`/path/to/config`>::
-	Use an alternate config file instead of the `/etc/makepkg.conf` default;
+	Use an alternate config file instead of the `@sysconfdir@/makepkg.conf` default;
 
 *-d, \--nodeps*::
 	Do not perform any dependency checks. This will let you override and
diff --git a/doc/pacman.conf.5.txt b/doc/pacman.conf.5.txt
index 0e8426a..f203600 100644
--- a/doc/pacman.conf.5.txt
+++ b/doc/pacman.conf.5.txt
@@ -35,7 +35,7 @@ NoUpgrade = etc/passwd etc/group etc/shadow
 NoUpgrade = etc/fstab
 
 [core]
-Include = /etc/pacman.d/core
+Include = @sysconfdir@/pacman.d/core
 
 [custom]
 Server = file:///home/pkgs
@@ -180,7 +180,7 @@ contain a file that lists the servers for that repository.
 # use this repository first
 Server = ftp://ftp.archlinux.org/core/os/arch
 # next use servers as defined in the mirrorlist below
-Include = /etc/pacman.d/mirrorlist
+Include = @sysconfdir@/pacman.d/mirrorlist
 --------
 
 During parsing, pacman will define the `$repo` variable to the name of the
diff --git a/scripts/rankmirrors.sh.in b/scripts/rankmirrors.sh.in
index 0cd4c08..a0ff6d5 100644
--- a/scripts/rankmirrors.sh.in
+++ b/scripts/rankmirrors.sh.in
@@ -25,7 +25,7 @@ usage() {
 	echo "Usage: rankmirrors [options] MIRRORFILE | URL"
 	echo
 	echo "Ranks pacman mirrors by their connection and opening speed. Pacman mirror"
-	echo "files are located in /etc/pacman.d/. It can also rank one mirror if the URL is"
+	echo "files are located in @sysconfdir@/pacman.d/. It can also rank one mirror if the URL is"
 	echo "provided."
 	echo
 	echo "Options:"
-- 
1.7.3.1



More information about the pacman-dev mailing list