get-rommanager: Prevent saving a broken download
Change-Id: I6a5553f64407b05c20febc1ae44abca52cd2fdea
diff --git a/get-rommanager b/get-rommanager
index 43bd70e..19a0941 100755
--- a/get-rommanager
+++ b/get-rommanager
@@ -1,2 +1,16 @@
-mkdir -p `dirname $0`/proprietary
-curl -L -o `dirname $0`/proprietary/RomManager.apk -O -L http://mirror.kanged.net/recoveries/RomManager.apk
+url=http://mirrorbrain.cyanogenmod.com/cm/recoveries/RomManager.apk
+apk=RomManager.apk
+dir=`dirname $0`/proprietary
+mkdir -p $dir
+curl -Lo $dir/$apk.new $url || exit $?
+mime=`file -b --mime-type $dir/$apk.new`
+if [ "$mime" = "application/zip" ]
+then
+ mv $dir/$apk.new $dir/$apk
+ file --mime-type $dir/$apk
+else
+ echo -n "$dir/$apk.new: "
+ echo "$mime" | grep text && cat $dir/$apk.new
+ rm $dir/$apk.new
+ exit 1
+fi