Skip to content

Commit

Permalink
Fixed a bunch of compatibility problems.
Browse files Browse the repository at this point in the history
First and foremost 'which', we found out, is not POSIX.
It also doesn't have consistent bahaviour. At all.

So, we found 'command -v' is the same thing, and has defined behaviour.

Also, a small problem with eval, wherein apple was declared a whore.
  • Loading branch information
psycotica0 committed Apr 18, 2009
1 parent 54bf125 commit ffa1824
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
8 changes: 4 additions & 4 deletions getrepo.sh
Expand Up @@ -2,7 +2,7 @@

# Tell zsh we expect to be treated like an sh script
# zsh really should take the hint from the shebang line
if which emulate 1>&2; then
if command -v emulate 1>&2; then
emulate sh
fi

Expand Down Expand Up @@ -49,7 +49,7 @@ else
temp="."
fi
# Try to use mktemp
if which mktemp 1>&2; then
if command -v mktemp 1>&2; then
temp="`mktemp -d "$temp/tve-getrepo-$$-XXXXXX"`"
else
temp="$temp/tve-getrepo-$$-$RANDOM-$RANDOM" #$RANDOM is non-standard and likely blank on your shell
Expand All @@ -69,9 +69,9 @@ if [ "$ARCH" = "x86" ]; then
fi

# Find the network utility
if which wget 1>&2; then
if command -v wget 1>&2; then
GET="wget -q"
elif which curl 1>&2; then
elif command -v curl 1>&2; then
GET="curl -sfLO"
else
echo "You must have wget or curl installed." 1>&2
Expand Down
17 changes: 9 additions & 8 deletions install.sh
Expand Up @@ -2,7 +2,7 @@

# Tell zsh we expect to be treated like an sh script
# zsh really should take the hint from the shebang line
if which emulate 1>&2; then
if command -v emulate 1>&2; then
emulate sh
fi

Expand Down Expand Up @@ -43,17 +43,17 @@ if [ -z "$1" ]; then
fi

# Find the network utility
if which wget 1>&2; then
if command -v wget 1>&2; then
GET="wget -q -O -"
elif which curl 1>&2; then
elif command -v curl 1>&2; then
GET="curl -sfL"
else
echo "You must have wget or curl installed." 1>&2
exit 1
fi

# Verify the presence of oauthsign
if ! which oauthsign 1>&2; then
if ! command -v oauthsign 1>&2; then
echo "You need the oauthsign utility from oauth-utils installed to use this script." 1>&2
exit 1
fi
Expand Down Expand Up @@ -109,23 +109,23 @@ else
temp="."
fi
# Try to use mktemp
if which mktemp 1>&2; then
if command -v mktemp 1>&2; then
temp="`mktemp -d "$temp/tve-install-$$-XXXXXX"`"
else
temp="$temp/tve-install-$$-$RANDOM-$RANDOM" #$RANDOM is non-standard and likely blank on your shell
mkdir -p "$temp"
fi

# Determine if there is an external package manager to use
EXTERNAL="`which apt-get`"
EXTERNAL="`command -v apt-get`"
if [ $? != 0 ]; then
EXTERNAL=""
else
EXTERNAL="apt-get install -y"
fi

# Determine which command to use for installing internal packages
INTERNAL="`which dpkg`"
INTERNAL="`command -v dpkg`"
if [ $? != 0 -o "`whoami`" != "root" ]; then
INTERNAL="./undeb.sh"
else
Expand Down Expand Up @@ -154,7 +154,8 @@ do_install () {
# Sign the URL with oauth utils (oauthsign)
URL="`oauthsign -c $CONSUMER_TOKEN -C $CONSUMER_SECRET -t $TOKEN -T $SECRET "$URL"`"
# Get remote URL and download deb file with GET
if ! $GET "$URL" > "$temp/$2.deb"; then
# FIXME eval because Apple is a *whore*
if ! eval "$GET \"$URL\" > \"$temp/$2.deb\""; then
echo "Error downloading ${2}... Aborting..."
exit 1
fi
Expand Down
4 changes: 2 additions & 2 deletions remove.sh
Expand Up @@ -2,7 +2,7 @@

# Tell zsh we expect to be treated like an sh script
# zsh really should take the hint from the shebang line
if which emulate 1>&2; then
if command -v emulate 1>&2; then
emulate sh
fi

Expand Down Expand Up @@ -61,7 +61,7 @@ if ! mkdir -p "$LOGDIR"; then
fi

# Determine which command to use for installing internal packages
INTERNAL="`which dpkg`"
INTERNAL="`command -v dpkg`"
if [ $? != 0 -o "`whoami`" != "root" ]; then
INTERNAL="undeb"
else
Expand Down
22 changes: 11 additions & 11 deletions undeb.sh
Expand Up @@ -2,19 +2,19 @@

# Tell zsh we expect to be treated like an sh script
# zsh really should take the hint from the shebang line
if which emulate 1>&2; then
if command -v emulate 1>&2; then
emulate sh
fi

# Ensure we have neccesary utils (ar, tar)

AR=`which ar`
AR=`command -v ar`
if [ -z "$AR" ]; then
echo "You must have a POSIXly-compliant version of ar to use $0" 1>&2
exit 1
fi

TAR=`which tar`
TAR=`command -v tar`
if [ -z "$TAR" ]; then
echo "You must have a POSIXly-compliant version of tar to use $0" 1>&2
exit 1
Expand Down Expand Up @@ -43,7 +43,7 @@ else
fi

# Get a random directory name and try to create it
if which mktemp 1>&2; then # Try to use mktemp
if command -v mktemp 1>&2; then # Try to use mktemp
temp="`mktemp -d "$temp/undeb-$$-XXXXXX"`"
else
temp="$temp/undeb-$$-$RANDOM-$RANDOM" #$RANDOM is non-standard and likely blank on your shell
Expand Down Expand Up @@ -82,7 +82,7 @@ fi

# Find and verify PGP signature (currently only supports using GPG for this)
if [ -r "$temp/_gpgorigin" ]; then
if which gpg 1>&2; then
if command -v gpg 1>&2; then
if gpg --verify "$temp/_gpgorigin" "$temp/debian-binary" "$temp/control.tar"* "$temp/data.tar"*; then
echo "PGP signature found and verified." 1>&2
else
Expand All @@ -99,21 +99,21 @@ fi
if [ -f "$temp/control.tar" ]; then
echo "Not compressed, no decompression necessary."
elif [ -f "$temp/control.tar.gz" ]; then
GZIP="`which gzip`"
GZIP="`command -v gzip`"
if [ -z "$GZIP" ]; then
echo "You must have a version of gzip to unpack $1" 1>&2
exit 1
fi
"$GZIP" -d "$temp/control.tar.gz"
elif [ -f "$temp/control.tar.bz2" ]; then
BZIP2="`which bzip2`"
BZIP2="`command -v bzip2`"
if [ -z "$BZIP2" ]; then
echo "You must have a version of bzip2 to unpack $1" 1>&2
exit 1
fi
"$BZIP2" -d "$temp/control.tar.bz2"
elif [ -f "$temp/control.tar.bzip2" ]; then
BZIP2="`which bzip2`"
BZIP2="`command -v bzip2`"
if [ -z "$BZIP2" ]; then
echo "You must have a version of bzip2 to unpack $1" 1>&2
exit 1
Expand All @@ -137,21 +137,21 @@ fi
if [ -f "$temp/data.tar" ]; then
echo "Not compressed, no decompression necessary."
elif [ -f "$temp/data.tar.gz" ]; then
GZIP="`which gzip`"
GZIP="`command -v gzip`"
if [ -z "$GZIP" ]; then
echo "You must have a version of gzip to unpack $1" 1>&2
exit 1
fi
"$GZIP" -d "$temp/data.tar.gz"
elif [ -f "$temp/data.tar.bz2" ]; then
BZIP2="`which bzip2`"
BZIP2="`command -v bzip2`"
if [ -z "$BZIP2" ]; then
echo "You must have a version of bzip2 to unpack $1" 1>&2
exit 1
fi
"$BZIP2" -d "$temp/data.tar.bz2"
elif [ -f "$temp/data.tar.bzip2" ]; then
BZIP2="`which bzip2`"
BZIP2="`command -v bzip2`"
if [ -z "$BZIP2" ]; then
echo "You must have a version of bzip2 to unpack $1" 1>&2
exit 1
Expand Down
4 changes: 2 additions & 2 deletions xdebuild-pre.sh
Expand Up @@ -21,7 +21,7 @@ mkdir -p "./debian/$1/usr/share/doc/$1"

if [ -f ./configure ]; then
echo "Running configure..."
if ! which gcc; then
if ! command -v gcc; then
echo "No gcc found in PATH." 1>&2
exit 1
fi
Expand All @@ -30,7 +30,7 @@ fi

if [ -f ./Makefile ]; then
echo "Running make..."
if which make; then
if command -v make; then
make prefix="`pwd`/debian/$1/usr" install
fi
fi
Expand Down

0 comments on commit ffa1824

Please sign in to comment.