From 7b900401b6a8c648330750bf4cb3dea492c352db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20Hangh=C3=B8j=20Iversen?= Date: Fri, 28 Feb 2014 13:26:17 +0100 Subject: [PATCH] Install script exits on error It always removes the temporary file --- install.sh | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/install.sh b/install.sh index ed31e16..58f4630 100755 --- a/install.sh +++ b/install.sh @@ -1,24 +1,23 @@ #!/usr/bin/env sh - -if [ "$UID" -ne 0 ] - then echo "Please run as root" - exit -fi +set -e TMP=$(mktemp pirate-get-XXX) -if [ $(which python2.7) ] -then - echo "#!/usr/bin/env python2.7" > "$TMP" -elif [ `which python2` ] -then - echo "#!/usr/bin/env python2" > "$TMP" -else - echo "#!/usr/bin/env python" > "$TMP" -fi + +{ + if [ $(which python2.7) ] + then + echo "#!/usr/bin/env python2.7" > "$TMP" + elif [ `which python2` ] + then + echo "#!/usr/bin/env python2" > "$TMP" + else + echo "#!/usr/bin/env python" > "$TMP" + fi sed 1d $(dirname $0)/pirate-get.py >> "$TMP" -cp "$TMP" /usr/bin/pirate-get -chmod +x /usr/bin/pirate-get -chmod 755 /usr/bin/pirate-get -rm "$TMP" + cp "$TMP" /usr/bin/pirate-get && + chmod +x /usr/bin/pirate-get && + chmod 755 /usr/bin/pirate-get && + rm $TMP +} || rm $TMP