Skip to content

Instantly share code, notes, and snippets.

@GiorgioAresu
Created February 4, 2016 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GiorgioAresu/1998c2ca659fd7cff896 to your computer and use it in GitHub Desktop.
Save GiorgioAresu/1998c2ca659fd7cff896 to your computer and use it in GitHub Desktop.
Bash script to automatically download CM nightlies roms and accumulate them into a user-specified folder.
#!/bin/bash
Device=$1
Path=$2
if [ $# -ne 2 ] || [ $# == "--help" ] || [ $# == "-h" ]
then
echo Simple CM Nightlies downloader
echo
echo Usage: $(basename $0) device-name output-path
echo
echo Example: $(basename $0) falcon "/home/user/Moto G/CM13/"
echo
exit 1
fi
if [ ! -d "$Path" ]
then
echo "The specified folder does not exist"
exit 1
fi
if [ ! -w "$Path" ]
then
echo "The specified folder is not writable"
exit 1
fi
Url="https://download.cyanogenmod.org"`curl -ks "https://download.cyanogenmod.org/?device="$Device | grep $Device.zip | head -n 1 | cut -d'"' -f2`
LatestDate=$(echo $Url | cut -d- -f 3)
Latest=$(echo $Url | cut -d/ -f 7)
File=$(echo $Path$Latest)
if [ -f "$File" ];
then
echo "File $FILE exists. Skipping..."
exit 0
else
echo "File $FILE does not exist. Downloading..."
curl -Lks -o "$File" "$Url"
if [ -f "$File" ];
then
echo "File downloaded."
echo "Changing Permissions..."
chmod 666 "$File"
echo "Done."
exit 0
else
echo "Couldn't download file to: \"$File\""
echo "Error."
exit 2
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment