#!/bin/bash # Copyright (c) 2011, Piotr Karbowski # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are # permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice, this # list of conditions and the following disclaimer in the documentation and/or other # materials provided with the distribution. # * Neither the name of the Piotr Karbowski nor the names of its contributors may be # used to endorse or promote products derived from this software without specific # prior written permission. baseurl='http://grsecurity.net' curl_args='--ipv4 -s' basename="${0##*/}" scriptpath="$(readlink -f $0)" workdir="${scriptpath%/${basename}}" cd "${workdir}" || exit 1 if [ -f "${workdir}/lock" ]; then exit 2; fi touch "${workdir}/lock" while read line; do if [[ "${line}" =~ grsecurity-[0-9\.\-]+\.patch$ ]]; then grsecurity_files+=( "${line##*/}" ) fi if [[ "${line}" =~ gradm-[0-9\.\-]+\.tar\.gz$ ]]; then gradm_files+=( "${line##*/}" ) fi done < <(curl ${curl_args} "${baseurl}/test.php" | awk -v RS='"' '!(--p){print}/href=$/{p=1}' ) # grsecurity patches. for item in "${grsecurity_files[@]}"; do if ! [ -f "test/${item}" ]; then printf 'Downloading %s ...\n' "${item}" curl ${curl_args} "${baseurl}/test/${item}" > "${workdir}/test/${item}" printf 'Downloading %s ...\n' "${item}.sig" curl ${curl_args} "${baseurl}/test/${item}.sig" > "${workdir}/test/${item}.sig" new_grsecurity_patches+=( "${item}" ) fi done; unset item date="$(date '+%d-%m-%Y %H:%M')" # If array have at least one element. if [ "${#new_grsecurity_patches[@]}" -gt '0' ]; then printf 'Downloading changelog-test.txt ...\n' curl ${curl_args} "${baseurl}/changelog-test.txt" > "${workdir}/test/changelog-test.txt" git add "${workdir}/test/" && git commit "${workdir}/test/" -m \ "$(printf 'grsec-scrape autocommit. %s new patch(es).\n\n' "${#new_grsecurity_patches[@]}"; printf 'New patch: %s\n' "${new_grsecurity_patches[@]}" )" git push fi rm "${workdir}/lock"