summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Santos (javamonger) <daniel.santos@pobox.com>2009-09-03 20:36:13 +0000
committerDaniel Santos (javamonger) <daniel.santos@pobox.com>2009-09-03 20:36:13 +0000
commitef51b06d347126567d696c3e2c90b27377213787 (patch)
tree6fdac896dc97f1fbd3ca8229a41ea4a802d75296 /net-misc/moblock/files/0.8-r1/moblock-update
parentmedia-radio/ibp: tested on amd64 (diff)
downloadsunrise-ef51b06d347126567d696c3e2c90b27377213787.tar.gz
sunrise-ef51b06d347126567d696c3e2c90b27377213787.tar.bz2
sunrise-ef51b06d347126567d696c3e2c90b27377213787.zip
net-misc/moblock: Fixes and Enhancements
svn path=/sunrise/; revision=9162
Diffstat (limited to 'net-misc/moblock/files/0.8-r1/moblock-update')
-rw-r--r--net-misc/moblock/files/0.8-r1/moblock-update180
1 files changed, 0 insertions, 180 deletions
diff --git a/net-misc/moblock/files/0.8-r1/moblock-update b/net-misc/moblock/files/0.8-r1/moblock-update
deleted file mode 100644
index eb5415765..000000000
--- a/net-misc/moblock/files/0.8-r1/moblock-update
+++ /dev/null
@@ -1,180 +0,0 @@
-#!/bin/bash
-
-source /etc/conf.d/moblock
-source /etc/init.d/functions.sh
-
-log_file=/var/log/moblock-update.log
-tmp_dir=/tmp/moblock-update.$$
-
-typeset -i successful_dl_count=0
-typeset -i failed_dl_count=0
-typeset -i FAIL=0
-
-cleanup() {
- log_msg "$0 exiting.
-
--------------------------------------------------------------------------------
-
-
-"
- rm -rf ${tmp_dir}
-}
-
-die() {
- eerror "Update failed: $@" | tee -a ${log_file}
- eerror "See /var/log/moblock-update.log for details."
- cleanup
- exit 1;
-}
-
-log_msg() {
- echo -e "$(date): $@" >> ${log_file}
-}
-
-init() {
- if [ -z "${BLOCKLISTSERVERS}" ]; then
- eerror "There is no BLOCKLISTSERVERS defined in /etc/conf.d/moblock."
- eindent
- eerror "Please set this variable to the list of servers you wish to"
- eerror "download from."
- eoutdent
-
- FAIL=1
- fi
-
- if [ -z "${BLOCKLISTS}" ]; then
- eerror "There is no BLOCKLISTS defined in /etc/conf.d/moblock."
- eindent
- eerror "Please set this variable to the lists you wish to use."
- eoutdent
-
- FAIL=1
- fi
-
- if [ -z "${BLOCKLISTFILE}" ]; then
- eerror "There is no BLOCKLISTFILE defined in /etc/conf.d/moblock."
- eindent
- eerror "Please set this variable to the file you wish to output the"
- eerror "merged block list to."
- eoutdent
-
- FAIL=1
- fi
-
- if [ -z "${BLOCKLISTDIR}" ]; then
- eerror "There is no BLOCKLISTDIR defined in /etc/conf.d/moblock."
- eindent
- eerror "Please set this variable to the directory you wish to store"
- eerror "the downloaded lists in."
- eoutdent
-
- FAIL=1
- fi
-
- [ ${FAIL} -eq 0 ] || die "invalid configuration"
-}
-
-# Iterate through servers until we get one to work or they all fail.
-getAFile() {
- local tmp_file=${tmp_dir}/${1}.wget.log
- for base_url in ${BLOCKLISTSERVERS}; do
- log_msg "Attempting to downloading ${1}.${BLOCKLISTSUFFIX} from location ${base_url}"
- if wget -P ${BLOCKLISTDIR} \
- -N ${base_url}/${1}.${BLOCKLISTSUFFIX} \
- -a ${tmp_file}; then
- rm ${tmp_file}
- return 0
- fi
- done
-
- log_msg "Failed to download ${1}.${BLOCKLISTSUFFIX}.
-${BAD}wget output ---------->${NORMAL}
-$(cat ${tmp_file})
-${BAD}<---------- end of wget output${NORMAL}"
- rm ${tmp_file}
- return 1
-}
-
-getBlocklists() {
- einfo Downloading lists...
- eindent
-
- for i in ${BLOCKLISTS}; do
- ebegin "Downloading ${i}" | tee -a ${log_file}
-
- if getAFile $i; then
- successful_dl_count=${successful_dl_count}+1
- eend 0 | tee -a ${log_file}
- else
- failed_dl_count=${failed_dl_count}+1
- eend 1 | tee -a ${log_file}
- fi
- done
-
- eoutdent
-
- if [ ${failed_dl_count} -ne 0 ]; then
- if [ ${successful_dl_count} -eq 0 ]; then
- die "All downloads failed"
- else
- ewarn "WARNING: ${failed_dl_count} downloads failed! See /var/log/moblock-update.log" \
- | tee -a ${log_file}
- ewarn "for details. Previous blocklists will be used failed items." \
- | tee -a ${log_file}
- fi
- fi
-}
-
-mergeFiles() {
- einfo Unpacking and merging lists...
- eindent
-
- local new_p2p_file=${tmp_dir}/new.p2p
-
- for i in ${BLOCKLISTS}; do
- ebegin Merging ${i} | tee -a ${log_file}
-
- gunzip -c ${BLOCKLISTDIR}/${i}.${BLOCKLISTSUFFIX} >> ${new_p2p_file} 2>>${log_file} \
- || die "Failed to extract list '${i}'"
-
- eend $? | tee -a ${log_file}
- done
-
- mv ${new_p2p_file} ${BLOCKLISTFILE}
-
- eoutdent
-}
-
-reloadList() {
- moblock_pid=$(cat /var/run/moblock.pid 2>/dev/null)
-
- if ps -p ${moblock_pid} > /dev/null 2>&1; then
- einfo "Reloading block list"
- kill -s HUP ${moblock_pid}
- eend $?
- fi
-}
-
-main() {
- mkdir -p ${BLOCKLISTDIR} || die "Failed to create dir ${BLOCKLISTDIR}."
- mkdir -p ${tmp_dir} || die "Failed to create dir ${tmp_dir}"
-
- einfo "Updating moblock..." | tee -a ${log_file}
- eindent
- log_msg "$0 initiated."
-
- getBlocklists
- mergeFiles
- reloadList | tee -a ${log_file}
-
- eoutdent
- if [ ${failed_dl_count} -eq 0 ]; then
- einfo "MoBlock update completed successfully." | tee -a ${log_file}
- else
- ewarn "MoBlock update partially successful." | tee -a ${log_file}
- fi
- cleanup
-}
-
-main
-