Skip to content

Instantly share code, notes, and snippets.

@SpiritCroc
Created September 11, 2016 06:58
Show Gist options
  • Save SpiritCroc/8813be8afdcb4c35120083629d747156 to your computer and use it in GitHub Desktop.
Save SpiritCroc/8813be8afdcb4c35120083629d747156 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Settings
data_folder="/home/spiritcroc/ROMs/scripts/sonyaospbuild/"
n_patch_script="/home/spiritcroc/ROMs/scripts/sony_n_patch.sh"
m_patch_script="/home/spiritcroc/ROMs/scripts/sony_mm_patch.sh"
# Files to get diff
n_instructions="n_instruct"
n_init="n_init"
n_manif="n_manif"
n_script="n_script"
m_instructions="m_instruct"
m_init="m_init"
m_manif="m_manif"
m_script="m_script"
# Configuration
aosp_n_buid_instructions="http://developer.sonymobile.com/open-devices/aosp-build-instructions/how-to-build-aosp-nougat-for-unlocked-xperia-devices/#build-aosp-nougat-7-0"
aosp_n_html="index.html"
aosp_m_buid_instructions="http://developer.sonymobile.com/open-devices/aosp-build-instructions/how-to-build-aosp-marshmallow-for-unlocked-xperia-devices/"
aosp_m_html="index.html"
# $1: filename
# $2: filename used for diff
create_backup() {
if [ -f "$1" ]; then
if [ -f "$2" ]; then
bak_date=$(date -r "$1" +%Y%m%d_%H%M)
mv "$2" "$1_$bak_date"
fi
mv "$1" "$2"
fi
}
# $1: $X_instructions
get_init() {
init=$(cat "$1" | recode html | tr -d '\r' | tr '\n' '\r' | sed 's/.*\(repo init.*\)<\/pre>\r<p><strong>Note!<\/strong> The downloaded data is around 20 GB.*/\1/' | tr '\r' '\n')
}
# $1: $X_instructions
get_manif() {
manif=$(cat "$1" | recode html | tr -d '\r' | tr '\n' '\r' | sed 's/.*\(<manifest>.*<\/manifest>\).*/\1/' | tr '\r' '\n')
}
# $1: $X_instructions
get_script() {
script=$(cat "$1" | tr -d '\r' | tr '\n' '\r' | sed 's/.*<li>In a terminal window, enter:\r<pre class=\"prettyprint\">\(.*\)<\/pre>\r<\/li>\r<\/ol>.*/\1/' | tr '\r' '\n' | recode html)
}
# $1: $aosp_X_buid_instructions
# $2: $aosp_X_html
# $3: $X_instructions
# $4: $X_manif
# $5: $X_script
# $6: $X_patch_script
# $7: $X_init
update_instr() {
wget -q "$1"
old="$3_old"
create_backup "$3" "$old"
mv "$2" "$3"
get_init $3
old_init="$7_old"
create_backup "$7" "$old_init"
echo "$init" > "$7"
echo "Init changes:"
diff "$7" "$old_init"
echo "End of init changes"
get_manif "$3"
old_manif="$4_old"
create_backup "$4" "$old_manif"
echo "$manif" > "$4"
echo "Manifest changes:"
diff "$4" "$old_manif"
echo "End of manifest changes"
get_script "$3"
old_script="$5_old"
create_backup "$5" "$old_script"
echo "$script" > "$5"
echo "Script changes:"
diff "$5" "$old_script"
echo "End of script changes"
script_location="$6"
if [ ! -f "$script_location" ]; then
touch "$script_location"
chmod a+x "$script_location"
fi
echo "#!/bin/bash" > $script_location
echo "" >> $script_location
echo "$script" >> $script_location
echo "Updated script"
}
cd "$data_folder"
echo "Update M instructions..."
update_instr $aosp_m_buid_instructions $aosp_m_html $m_instructions $m_manif $m_script $m_patch_script $m_init
echo "Update N instructions..."
update_instr $aosp_n_buid_instructions $aosp_n_html $n_instructions $n_manif $n_script $n_patch_script $n_init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment