Wednesday, November 13, 2013

Release 0.1

After doing some spending some time with my code given that the presentation day was upon me, I managed to get the most of the code up and running with the exception of the last command koji that was not accepting my keys.

There are other things to tinker in the code but for 0.1 this should suffice.

#!/bin/bash


#Check if the file contain the commit long exists
#If it does not exist create the file

if [ ! -f ./branches ]; then
        touch branches
fi

if [ ! -f ./long_commit ]; then
        touch long_commit
fi

if [ ! -f ./page_source ]; then
        touch page_source
fi


# Retrieve branches from github
wget -qO- https://github.com/raspberrypi/linux | cat | grep 'data-name="rpi' | cut -d '"' -f2 > ./branches
# Delete the patches branci that way the latest branch is last
sed -i '$ d' ./branches

# store in a variable the latest branch
branch=$(tail -1 ./branches)
# There are some issues with 3.12.y so I am statically using 3.11.y
branch="rpi-3.11.y"

# Storing url for use with wget
url=$(echo "https://github.com/raspberrypi/linux/tree/$branch/kernel")
wget -qO- $url > ./page_source

commit_date=$( cat ./page_source | grep 'committed <time class="js-relative-date"' | cut -d '"' -f6 | cut -d ' ' -f1 | cut -d '-' -f1-3 --output-delimiter='' )
long_commit=$( cat ./page_source | grep 'js-zeroclipboard zeroclipboard-link' | cut -d '"' -f4)
short_commit=$( echo $long_commit | cut -c 1-7)
stored_long_commit=$(cat ./long_commit)

# If the file is empty store the long_commit variable
# Otherwise compare the long commit form Github with the one in the file
# If they are the same do nothing and exit
# If they are different store the new value in the file and download the new kernel

if [ ! -s ./long_commit ]; then
        echo $long_commit > ./long_commit

else
        if [ "$long_commit" == "$stored_long_commit" ] ; then
                #Nothing to do
                flag=0
                echo "There is no new kernel"

        else
                # Replace the old commit with new commit
                echo $long_commit > ./long_commit
                #Proceed to build kernel
                flag=1
        fi
fi


if [ $flag -eq 1 ]; then
        # Download previous built kernel to retrieve some necessary files including the spec file
        wget http://japan.proximity.on.ca/kojifiles/packages/raspberrypi-kernel/3.11.6/4.20131023git10bc582.rpfr19/src/raspberrypi-kernel-3.11.6-4.20131023git10bc582.rpfr19.src.rpm

        # Download new kernel
        new_kernel_url=$(echo "https://github.com/raspberrypi/linux/tarball/$long_commit")
        wget $new_kernel_url

        rpmdev-setuptree
        rpmdev-wipetree

        rpm2cpio raspberrypi-kernel-3.11.6-4.20131023git10bc582.rpfr19.src.rpm | cpio -idmv
#       rpm -i raspberrypi-kernel-3.11.6-4.20131023git10bc582.rpfr19.src.rpm

        # Modifiying SPEC file with info from the new kernel
        sed -i "s/commit_date\ .*/commit_date $commit_date/" raspberrypi-kernel.spec
        sed -i "s/commit_short\ .*/commit_short $short_commit/" raspberrypi-kernel.spec
        sed -i "s/commit_long\ .*/commit_long $long_commit/" raspberrypi-kernel.spec

        # Copy spec file to ~/rpmbuild/SPECS
        cp raspberrypi-kernel.spec ~/rpmbuild/SPECS/

        # Bump SPEC
        rpmdev-bumpspec -c "Updated to latest commit" ~/rpmbuild/SPECS/raspberrypi-kernel.spec

        # Copye source files to ~/rpmbuild/SOURCES
        cp first32k.bin.bz2 ~/rpmbuild/SOURCES
        newfile=$(echo "pidora-config-3.11.6-"$short_commit".bz2")
        file=$( ls -l | grep 'pidora-config' | awk '{print $9}' )
        cp $file $newfile
        mv $newfile ~/rpmbuild/SOURCES

        cp "$long_commit" ~/rpmbuild/SOURCES

        # Build rpm source package
        rpmbuild -bs ~/rpmbuild/SPECS/raspberrypi-kernel.spec

        # Send Source Package to Koji
        koji -s 'http://japan.proximity.on.ca/kojihub' build f18-rpfr-updates-automated-build ~/rpmbuild/SRPMS/raspberrypi-kernel-3.11.6-5.20131013git3e1fee6.rpfr19.src.rpm
fi


There it is my code. I got to say, I was a rusty with bash

No comments:

Post a Comment