[arch-projects] [dbscripts] [PATCH 09/11] Consistently use "$(dirname "$(readlink -e "$0")")"

Luke Shumaker lukeshu at sbcglobal.net
Sun May 17 23:44:17 UTC 2015


From: Luke Shumaker <LukeShu at sbcglobal.net>

This does correct handling of
 - executing a program by symlink
 - any weird characters in the full path
 - I'm sure there's another case I thought about when I originally did
   this.
---
 cron-jobs/ftpdir-cleanup        | 4 ++--
 cron-jobs/integrity-check       | 2 +-
 cron-jobs/update-web-db         | 4 ++--
 db-move                         | 4 ++--
 db-remove                       | 4 ++--
 db-repo-add                     | 4 ++--
 db-repo-remove                  | 4 ++--
 db-update                       | 4 ++--
 test/test.d/create-filelists.sh | 2 +-
 test/test.d/db-move.sh          | 2 +-
 test/test.d/db-remove.sh        | 2 +-
 test/test.d/db-repo-add.sh      | 2 +-
 test/test.d/db-repo-remove.sh   | 2 +-
 test/test.d/db-update.sh        | 2 +-
 test/test.d/ftpdir-cleanup.sh   | 2 +-
 test/test.d/packages.sh         | 2 +-
 test/test.d/signed-packages.sh  | 2 +-
 test/test.d/sourceballs.sh      | 2 +-
 test/test.d/testing2x.sh        | 2 +-
 testing2x                       | 6 +++---
 20 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/cron-jobs/ftpdir-cleanup b/cron-jobs/ftpdir-cleanup
index f6487cf..4063c09 100755
--- a/cron-jobs/ftpdir-cleanup
+++ b/cron-jobs/ftpdir-cleanup
@@ -1,7 +1,7 @@
 #!/bin/bash
 
-. "$(dirname "$0")/../config"
-. "$(dirname "$0")/../db-functions"
+. "$(dirname "$(readlink -e "$0")")/../config"
+. "$(dirname "$(readlink -e "$0")")/../db-functions"
 
 clean_pkg() {
 	local pkg
diff --git a/cron-jobs/integrity-check b/cron-jobs/integrity-check
index 677c0d3..7459380 100755
--- a/cron-jobs/integrity-check
+++ b/cron-jobs/integrity-check
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-dirname="$(dirname "$0")"
+dirname="$(dirname "$(readlink -e "$0")")"
 
 . "${dirname}/../config"
 . "${dirname}/../db-functions"
diff --git a/cron-jobs/update-web-db b/cron-jobs/update-web-db
index 88bf464..c8bf74a 100755
--- a/cron-jobs/update-web-db
+++ b/cron-jobs/update-web-db
@@ -1,7 +1,7 @@
 #!/bin/bash
 
-. "$(dirname "$0")/../config"
-. "$(dirname "$0")/../db-functions"
+. "$(dirname "$(readlink -e "$0")")/../config"
+. "$(dirname "$(readlink -e "$0")")/../db-functions"
 
 # setup paths
 SPATH="/srv/http/archweb"
diff --git a/db-move b/db-move
index b589bca..a55dd50 100755
--- a/db-move
+++ b/db-move
@@ -1,7 +1,7 @@
 #!/bin/bash
 
-. "$(dirname "$0")/config"
-. "$(dirname "$0")/db-functions"
+. "$(dirname "$(readlink -e "$0")")/config"
+. "$(dirname "$(readlink -e "$0")")/db-functions"
 
 if [ $# -lt 3 ]; then
 	msg "usage: %s <repo-from> <repo-to> <pkgname|pkgbase> ..." "${0##*/}"
diff --git a/db-remove b/db-remove
index 59f2db0..9c86143 100755
--- a/db-remove
+++ b/db-remove
@@ -1,7 +1,7 @@
 #!/bin/bash
 
-. "$(dirname "$0")/config"
-. "$(dirname "$0")/db-functions"
+. "$(dirname "$(readlink -e "$0")")/config"
+. "$(dirname "$(readlink -e "$0")")/db-functions"
 
 if [ $# -lt 3 ]; then
 	msg "usage: %s <repo> <arch> <pkgname|pkgbase> ..." "${0##*/}"
diff --git a/db-repo-add b/db-repo-add
index 09ce865..4611bdf 100755
--- a/db-repo-add
+++ b/db-repo-add
@@ -1,7 +1,7 @@
 #!/bin/bash
 
-. "$(dirname "$0")/config"
-. "$(dirname "$0")/db-functions"
+. "$(dirname "$(readlink -e "$0")")/config"
+. "$(dirname "$(readlink -e "$0")")/db-functions"
 
 if [ $# -lt 3 ]; then
 	msg "usage: %s <repo> <arch> <pkgfile> ..." "${0##*/}"
diff --git a/db-repo-remove b/db-repo-remove
index 97a671b..aadc4ce 100755
--- a/db-repo-remove
+++ b/db-repo-remove
@@ -1,7 +1,7 @@
 #!/bin/bash
 
-. "$(dirname "$0")/config"
-. "$(dirname "$0")/db-functions"
+. "$(dirname "$(readlink -e "$0")")/config"
+. "$(dirname "$(readlink -e "$0")")/db-functions"
 
 if [ $# -lt 3 ]; then
 	msg "usage: %s <repo> <arch> <pkgname> ..." "${0##*/}"
diff --git a/db-update b/db-update
index 7f59ce7..8966f0e 100755
--- a/db-update
+++ b/db-update
@@ -1,7 +1,7 @@
 #!/bin/bash
 
-. "$(dirname "$0")/config"
-. "$(dirname "$0")/db-functions"
+. "$(dirname "$(readlink -e "$0")")/config"
+. "$(dirname "$(readlink -e "$0")")/db-functions"
 
 if [ $# -ge 1 ]; then
 	warning "Calling %s with a specific repository is no longer supported" "${0##*/}"
diff --git a/test/test.d/create-filelists.sh b/test/test.d/create-filelists.sh
index e16a8d1..21bf292 100755
--- a/test/test.d/create-filelists.sh
+++ b/test/test.d/create-filelists.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-curdir=$(readlink -e "$(dirname "$0")")
+curdir="$(dirname "$(readlink -e "$0")")"
 . "${curdir}/../lib/common.inc"
 
 testCreateSimpleFileLists() {
diff --git a/test/test.d/db-move.sh b/test/test.d/db-move.sh
index 410e222..4b4120e 100755
--- a/test/test.d/db-move.sh
+++ b/test/test.d/db-move.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-curdir=$(readlink -e "$(dirname "$0")")
+curdir="$(dirname "$(readlink -e "$0")")"
 . "${curdir}/../lib/common.inc"
 
 testMoveSimplePackages() {
diff --git a/test/test.d/db-remove.sh b/test/test.d/db-remove.sh
index 4fd5548..a391197 100755
--- a/test/test.d/db-remove.sh
+++ b/test/test.d/db-remove.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-curdir=$(readlink -e "$(dirname "$0")")
+curdir="$(dirname "$(readlink -e "$0")")"
 . "${curdir}/../lib/common.inc"
 
 testRemovePackages() {
diff --git a/test/test.d/db-repo-add.sh b/test/test.d/db-repo-add.sh
index 776c0a2..266a696 100755
--- a/test/test.d/db-repo-add.sh
+++ b/test/test.d/db-repo-add.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-curdir=$(readlink -e "$(dirname "$0")")
+curdir="$(dirname "$(readlink -e "$0")")"
 . "${curdir}/../lib/common.inc"
 
 testAddSimplePackages() {
diff --git a/test/test.d/db-repo-remove.sh b/test/test.d/db-repo-remove.sh
index fd69fa7..727188d 100755
--- a/test/test.d/db-repo-remove.sh
+++ b/test/test.d/db-repo-remove.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-curdir=$(readlink -e "$(dirname "$0")")
+curdir="$(dirname "$(readlink -e "$0")")"
 . "${curdir}/../lib/common.inc"
 
 testRemovePackages() {
diff --git a/test/test.d/db-update.sh b/test/test.d/db-update.sh
index 48c243d..ca4efe7 100755
--- a/test/test.d/db-update.sh
+++ b/test/test.d/db-update.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-curdir=$(readlink -e "$(dirname "$0")")
+curdir="$(dirname "$(readlink -e "$0")")"
 . "${curdir}/../lib/common.inc"
 
 testAddSimplePackages() {
diff --git a/test/test.d/ftpdir-cleanup.sh b/test/test.d/ftpdir-cleanup.sh
index 6902b9b..5a7afea 100755
--- a/test/test.d/ftpdir-cleanup.sh
+++ b/test/test.d/ftpdir-cleanup.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-curdir=$(readlink -e "$(dirname "$0")")
+curdir="$(dirname "$(readlink -e "$0")")"
 . "${curdir}/../lib/common.inc"
 
 testCleanupSimplePackages() {
diff --git a/test/test.d/packages.sh b/test/test.d/packages.sh
index 1a31a41..18266eb 100755
--- a/test/test.d/packages.sh
+++ b/test/test.d/packages.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-curdir=$(readlink -e "$(dirname "$0")")
+curdir="$(dirname "$(readlink -e "$0")")"
 . "${curdir}/../lib/common.inc"
 
 testPackages() {
diff --git a/test/test.d/signed-packages.sh b/test/test.d/signed-packages.sh
index 4eccb41..3ffe146 100755
--- a/test/test.d/signed-packages.sh
+++ b/test/test.d/signed-packages.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-curdir=$(readlink -e "$(dirname "$0")")
+curdir="$(dirname "$(readlink -e "$0")")"
 . "${curdir}/../lib/common.inc"
 
 testAddSignedPackage() {
diff --git a/test/test.d/sourceballs.sh b/test/test.d/sourceballs.sh
index 561169e..81c9265 100755
--- a/test/test.d/sourceballs.sh
+++ b/test/test.d/sourceballs.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-curdir=$(readlink -e "$(dirname "$0")")
+curdir="$(dirname "$(readlink -e "$0")")"
 . "${curdir}/../lib/common.inc"
 
 testSourceballs() {
diff --git a/test/test.d/testing2x.sh b/test/test.d/testing2x.sh
index 3bbd353..c611ce4 100755
--- a/test/test.d/testing2x.sh
+++ b/test/test.d/testing2x.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-curdir=$(readlink -e "$(dirname "$0")")
+curdir="$(dirname "$(readlink -e "$0")")"
 . "${curdir}/../lib/common.inc"
 
 testTesting2xAnyPackage() {
diff --git a/testing2x b/testing2x
index e269248..901c1b0 100755
--- a/testing2x
+++ b/testing2x
@@ -1,7 +1,7 @@
 #!/bin/bash
 
-. "$(dirname "$0")/config"
-. "$(dirname "$0")/db-functions"
+. "$(dirname "$(readlink -e "$0")")/config"
+. "$(dirname "$(readlink -e "$0")")/db-functions"
 
 if [ $# -lt 1 ]; then
 	msg "usage: %s <pkgname|pkgbase> ..." "${0##*/}"
@@ -54,7 +54,7 @@ for repo in  "${STABLE_REPOS[@]}"; do
 		repo_unlock "${repo}" "${pkgarch}"
 	done
 	if [ -n "${pkgs[${repo}]}" ]; then
-		"$(dirname "$0")/db-move" "${TESTING_REPO}" "${repo}" "${pkgs[${repo}]}"
+		"$(dirname "$(readlink -e "$0")")/db-move" "${TESTING_REPO}" "${repo}" "${pkgs[${repo}]}"
 	fi
 done
 
-- 
2.4.1


More information about the arch-projects mailing list