summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/url_check/README12
-rwxr-xr-xplugins/url_check/main254
-rw-r--r--plugins/url_check/ptxlib.bash351
3 files changed, 617 insertions, 0 deletions
diff --git a/plugins/url_check/README b/plugins/url_check/README
new file mode 100644
index 000000000..482cbe1e1
--- /dev/null
+++ b/plugins/url_check/README
@@ -0,0 +1,12 @@
+# this is a quick hack, but quite useful
+
+Usage: main OPTIONS
+
+ --help, -h this help
+ --check-all, -a check ALL packages
+
+plugins/url_check/main checks the availability of all needed source packages
+for the current project configuration. By default, packages
+will only be checked, if the corresponding switch in
+ptxdistrc is set to "y" (enabled in 'ptxdist menuconfig')
+
diff --git a/plugins/url_check/main b/plugins/url_check/main
new file mode 100755
index 000000000..3029a30ad
--- /dev/null
+++ b/plugins/url_check/main
@@ -0,0 +1,254 @@
+#!/bin/bash
+# ----------------------------------------------------------
+#
+# Script: PTXdist URL Checker
+# Rev: 1
+# Description:
+# Written by: Bjørn Bürger <b.buerger@pengutronix.de>
+# Changed: 2006-09-21 bbu
+# Docs: inline
+# Manpage: none
+#
+# ----------------------------------------------------------
+PREFIX="`basename $0` "
+# ----------------------------------------------------------
+# Short Documentation / Comments
+# ----------------------------------------------------------
+#
+# TODO:
+# build URL_CHECKER as host-tool in ptxdist.
+# Problem -> uses python => big and fat
+# OR find a lightweight alternative.
+#
+# Please note, that wget has problems w/ ftp links.
+#
+#
+
+# ----------------------------------------------------------
+# generic script settings
+# ----------------------------------------------------------
+#
+# The script domains - chose one or more of:
+# - dumb_tool
+# - tool
+# - development
+# - system_management
+#
+# PTX_SCRIPT_DOMAINS="dumb_tool"
+
+PTX_LIB_VERSION="2"
+
+# ----------------------------------------------------------
+# Default Configuration Options
+# ----------------------------------------------------------
+
+MKTEMP="mktemp"
+WHICH="which"
+GREP="grep"
+EGREP="egrep"
+CAT="cat"
+SED="sed"
+MKDIR="mkdir"
+
+LINKCHECKER_BIN="linkchecker"
+
+URL_CHECKER="$LINKCHECKER_BIN --no-warnings"
+# URL_CHECKER="wget --spider"
+
+PTXCONFIG="ptxconfig"
+
+logdir="`dirname $0`/log"
+logfile="$logdir/url_check_log"
+
+# ----------------------------------------------------------
+# Load ptx shell library and generic ptx configuration
+# ----------------------------------------------------------
+
+PTXLIB=`dirname $0`/ptxlib.bash
+
+if [ -e "$PTXLIB" ] ; then
+ . $PTXLIB
+else
+ echo "ERROR: ptxlib not found"
+ exit 1
+fi
+
+# ==========================================================
+# Temporary files
+# ==========================================================
+
+TMPDIR="`$MKTEMP -d /tmp/url_check_plugin.XXXXXXXXXX`" || echo "could not create TMPDIR"
+
+ptx_debug "TMPDIR is $TMPDIR"
+
+# ==========================================================
+# Traps
+# ==========================================================
+
+[ -e "$TMPDIR/on_exit_reverse.sh" ] || echo "echo" > $TMPDIR/on_exit_reverse.sh
+
+if [ "$DEBUG" = "true" ]; then
+ ptx_debug "trap function: deleting temporary files..."
+ trap '[ -e "$TMPDIR/on_exit_reverse.sh" ] && sh $TMPDIR/on_exit_reverse.sh ; rm -rvf /tmp/$(basename $TMPDIR)' EXIT
+else
+ trap '[ -e "$TMPDIR/on_exit_reverse.sh" ] && sh $TMPDIR/on_exit_reverse.sh ; rm -rf /tmp/$(basename $TMPDIR)' EXIT
+fi
+
+# ----------------------------------------------------------
+# Default Dependency check
+# ----------------------------------------------------------
+
+dependency_check_dirs_depends=""
+dependency_check_files_depends="$PTXCONFIG"
+dependency_check_tools_depends="$LINKCHECKER_BIN $MKTEMP"
+
+ptx_dependency_check
+
+# ==========================================================
+# Option Parser
+# ==========================================================
+
+Usage() {
+cat <<-EOF
+
+Usage: `basename "$0"` OPTIONS
+
+ --help, -h this help
+ --check-all, -a check ALL packages
+
+$0 checks the availability of all needed source packages
+for the current project configuration. By default, packages
+will only be checked, if the corresponding switch in
+ptxdistrc is set to "y" (enabled in 'ptxdist menuconfig')
+
+EOF
+}
+
+# Parser
+# ------
+# option no argument
+# option: required argument
+# option:: optional argument
+
+TEMP=`getopt --options h,a \
+ --longoptions="help,check-all" \
+ -n "$0" -- "$@"`
+if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
+eval set -- "$TEMP"
+
+while true ; do
+ case "$1" in
+ -h|--help)
+ [ -z "$action" ]
+ action="help" ;
+ shift
+ ;;
+ -a|--check-all)
+ [ -z "$action" ]
+ action="check_all" ;
+ shift
+ ;;
+ --) shift ; break ;;
+ *) echo "Internal error!" ; exit 1 ;;
+ esac
+done
+
+# ==========================================================
+# Script Variables
+# ==========================================================
+
+# none
+
+# ==========================================================
+# Script Functions
+# ==========================================================
+
+init(){
+ # choose the right ptxdist version:
+ PTXDIST=$(echo `$GREP PTXCONF_CONFIGFILE_VERSION $PTXCONFIG` \; echo "ptxdist-\$PTXCONF_CONFIGFILE_VERSION" | sh)
+ PTXDIST_BIN="`$WHICH $PTXDIST`"
+ ptx_debug "PTXDIST is: $PTXDIST ($PTXDIST_BIN)"
+ if [ "$1" = "all" ]; then
+ # get all package labels
+ # (PACKAGES-y contains all activated packages)
+ # (PACKAGES- contains all deactivated packages)
+ YESPACKAGES=`$PTXDIST print PACKAGES-y | sed -e s/'PACKAGES-y is "'//g -e s/\"//g | tr "a-z-" "A-Z_"`
+ NOPACKAGES=`$PTXDIST print PACKAGES- | sed -e s/'PACKAGES- is "'//g -e s/\"//g | tr "a-z-" "A-Z_"`
+ else
+ # get configured package labels
+ # (PACKAGES-y contains all activated packages)
+ YESPACKAGES=`$PTXDIST print PACKAGES-y | sed -e s/'PACKAGES-y is "'//g -e s/\"//g | tr "a-z-" "A-Z_"`
+ NOPACKAGES=""
+ fi
+ PACKAGES="$YESPACKAGES $NOPACKAGES"
+}
+
+create_url_list(){
+ echo "creating list of download URLS for `echo $PACKAGES | wc -w` packages (This may take a while!)"
+ for target in $PACKAGES; do
+ $PTXDIST print ${target}_URL | $SED -e s/.*is\ \"//g -e s/\"//g >> $TMPDIR/urllist
+ echo -n "."
+ done
+ echo "done"
+}
+
+test_urls(){
+ egrep -v "^#|^$|^[[:space:]]" $TMPDIR/urllist \
+ | while read line; do
+ $URL_CHECKER $line >$TMPDIR/errormsg 2>&1
+ case $? in
+ 0)
+ echo " [ OK ] $line"
+ ;;
+ *)
+ echo ""
+ echo " [ FAIL ] $line"
+ echo ""
+ $CAT $TMPDIR/errormsg | $GREP -A 10 "Start checking at"
+ echo ""
+ ;;
+ esac
+ done
+}
+
+runner(){
+ $MKDIR -p $logdir
+ case $? in
+ 0)
+ test_urls | tee $logfile
+ echo "LOGFILE is --> $logfile"
+ ;;
+ *)
+ test_urls
+ ;;
+ esac
+}
+
+# ==========================================================
+# Script Main
+# ==========================================================
+
+case "$action" in
+ help)
+ Usage
+ ;;
+ check_all)
+ init all
+ create_url_list >&2
+ runner
+ ;;
+ *)
+ init
+ create_url_list >&2
+ runner
+ ;;
+esac
+
+# ==========================================================
+# Cleanup
+# ==========================================================
+
+# unconfigured - done by trap function
+# ----------------------------------------------------------
+# End
+# ----------------------------------------------------------
diff --git a/plugins/url_check/ptxlib.bash b/plugins/url_check/ptxlib.bash
new file mode 100644
index 000000000..50249916d
--- /dev/null
+++ b/plugins/url_check/ptxlib.bash
@@ -0,0 +1,351 @@
+#!/bin/bash
+# -----------------------------------------------------
+# Description: Basic Script Functions
+# Author: Bjørn Bürger <b.buerger@pengutronix.de>
+# Date: Wed Mar 21 17:03:39 CET 2007
+# -----------------------------------------------------
+
+PTXLIB="true"
+MY_VERSION="2"
+
+if [ "$PTX_LIB_VERSION" -lt "$MY_VERSION" ] ; then
+ echo "WARNING: ptxlib.bash not compatible"
+ echo "WARNING: please audit your script"
+ exit 1
+fi
+
+FULLARGS="$@"
+DEBUG=${DEBUG:="false"}
+
+#
+# customized exit functions
+#
+# $1 --> Error Message
+# $2 --> Exit Code
+#
+ptx_exit(){
+ echo "$0: $1"
+ exit $2
+}
+ptx_exit_silent(){
+ ptx_debug "$0: $1"
+ exit $2
+}
+
+#
+# print out error message and exit with status 1
+#
+# $1: error message
+# ${PREFIX}: to be printed before message
+#
+ptx_bailout () {
+ echo "${PREFIX}error: $1" >&2
+ exit 1
+}
+
+
+#
+# print out warning message
+#
+# $1: warning message
+# ${PREFIX}: to be printed before message
+#
+ptx_warning() {
+ echo "${PREFIX}warning: $1" >&2
+}
+
+#
+# print out classic message
+#
+# $1: warning message
+# ${PREFIX}: to be printed before message
+#
+ptx_message() {
+ echo "${PREFIX}: $1" >&1
+}
+
+ptx_message_n() {
+ if [ -n "$PREFIX" ]; then
+ echo -n "${PREFIX}: $1" >&1
+ else
+ echo -n "$1" >&1
+ fi
+}
+
+#
+# Debugging Output
+#
+ptx_debug(){
+ [ "$DEBUG" = "true" ] && echo "$0: $1" >&2
+}
+ptx_debug "Debugging is enabled - Turn off with DEBUG=false"
+
+
+#
+# check if a previously executed pipe returned an error
+#
+ptx_check_pipe_status() {
+ for i in "${PIPESTATUS[@]}"; do [ $i -gt 0 ] && {
+ echo
+ echo "error: a command in the pipe returned $i, bailing out"
+ echo
+ exit $i
+ }
+ done
+}
+
+#
+# present a choice [y/n] and execute command
+#
+# $1: question / message
+# $2: command
+# $3: yes message
+# $4: no message
+# ${PREFIX}: to be printed before message
+#
+#
+ptx_yesno_choice(){
+ ptx_debug "Message: $1"
+ ptx_debug "Command: $2"
+ dialog --yesno "$1" 0 0
+ case $? in
+ 0)
+ ptx_message "${PREFIX} [YES] - $3"
+ $2 || ptx_error "command $2 failed"
+ ;;
+ *)
+ ptx_warning "${PREFIX} [NO] - $4"
+ ;;
+ esac
+}
+
+#
+# create a directory
+#
+ptx_check_create_dir(){
+ [ -d "$1" ] || ptx_yesno_choice "$1 does not exist, create it?" "mkdir -pv $1" "[SUCCESS]" "[ABORTED]"
+}
+
+#
+# dependency check for needed files
+#
+# if any one of these variables is
+# set, a dependency check is performed:
+#
+# dependency_check_files_recommends
+# dependency_check_files_depends
+# dependency_check_files_conflicts
+#
+ptx_dependency_check_files(){
+ [ -z "$dependency_check_files_recommends" ] && ptx_debug "[file check] no file recommendation defined"
+ for file in $dependency_check_files_recommends; do
+ test -e $file
+ case $? in
+ 0)
+ ptx_debug "[file check] This Script recommends $file: OK"
+ ;;
+ *)
+ ptx_warning "[file check] This Script recommends $file: FILE NOT FOUND"
+ ;;
+ esac
+ done
+ [ -z "$dependency_check_files_depends" ] && ptx_debug "[file check] no file dependency defined"
+ for file in $dependency_check_files_depends; do
+ test -e $file
+ case $? in
+ 0)
+ ptx_debug "[file check] This Script depends on $file: OK"
+ ;;
+ *)
+ ptx_bailout "[file check] This Script depends on $file: FILE NOT FOUND"
+ ;;
+ esac
+ done
+ [ -z "$dependency_check_files_conflicts" ] && ptx_debug "[file check] no file conflict defined"
+ for file in $dependency_check_files_conflicts; do
+ test -e $file
+ case $? in
+ 0)
+ ptx_bailout "[file check] This Script conflicts with $file: FILE EXISTS"
+ ;;
+ *)
+ ptx_debug "[file check] This Script conflicts with $file: OK (does not exist)"
+ ;;
+ esac
+ done
+}
+
+#
+# dependency check for needed directories
+#
+# if any one of these variables is
+# set, a dependency check is performed:
+#
+# dependency_check_dirs_recommends
+# dependency_check_dirs_depends
+# dependency_check_dirs_conflicts
+#
+ptx_dependency_check_dirs(){
+ [ -z "$dependency_check_dirs_recommends" ] && ptx_debug "[dir check] no directory recommendation defined"
+ for directory in $dependency_check_dirs_recommends; do
+ test -d $directory
+ case $? in
+ 0)
+ ptx_debug "[dir check] This Script recommends $directory: OK"
+ ;;
+ *)
+ ptx_warning "[dir check] This Script recommends $directory: directory NOT FOUND"
+ ;;
+ esac
+ done
+ [ -z "$dependency_check_dirs_depends" ] && ptx_debug "[dir check] no directory dependency defined"
+ for directory in $dependency_check_dirs_depends; do
+ test -d $directory
+ case $? in
+ 0)
+ ptx_debug "[dir check] This Script depends on $directory: OK"
+ ;;
+ *)
+ ptx_bailout "[dir check] This Script depends on $directory: directory NOT FOUND"
+ ;;
+ esac
+ done
+ [ -z "$dependency_check_dirs_conflicts" ] && ptx_debug "[dir check] no directory conflict defined"
+ for directory in $dependency_check_dirs_conflicts; do
+ test -d $directory
+ case $? in
+ 0)
+ ptx_bailout "[dir check] This Script conflicts with $directory: directory EXISTS"
+ ;;
+ *)
+ ptx_debug "[dir check] This Script conflicts with $directory: OK (does not exist)"
+ ;;
+ esac
+ done
+}
+
+#
+# dependency check for needed tools
+#
+# if any one of these variables is
+# set, a dependency check is performed:
+#
+# dependency_check_tools_recommends
+# dependency_check_tools_depends
+# dependency_check_tools_conflicts
+#
+ptx_dependency_check_tools(){
+ [ -z "$dependency_check_files_recommends" ] && ptx_debug "[file check] no tool recommendation defined"
+ for tool in $dependency_check_tools_recommends; do
+ which $tool >/dev/null 2>&1
+ case $? in
+ 0)
+ ptx_debug "[tool check] This Script recommends $tool: OK"
+ ;;
+ *)
+ ptx_warning "[tool check] This Script recommends $tool: MISSING"
+ ;;
+ esac
+ done
+ [ -z "$dependency_check_tools_depends" ] && ptx_debug "[file check] no tool dependency defined"
+ for tool in $dependency_check_tools_depends; do
+ which $tool >/dev/null 2>&1
+ case $? in
+ 0)
+ ptx_debug "[tool check] This Script depends on $tool: OK"
+ ;;
+ *)
+ ptx_bailout "[tool check] This Script depends on $tool: MISSING"
+ ;;
+ esac
+ done
+ [ -z "$dependency_check_tools_conflicts" ] && ptx_debug "[file check] no file conflict defined"
+ for tool in $dependency_check_tools_conflicts; do
+ which $tool >/dev/null 2>&1
+ case $? in
+ 0)
+ ptx_bailout "[tool check] This Script conflicts with on $tool: CONFLICT FOUND"
+ ;;
+ *)
+ ptx_debug "[tool check] This Script conflicts with $tool: OK"
+ ;;
+ esac
+ done
+}
+
+ptx_dependency_check_hostname(){
+ [ -z "$dependency_check_hostname_recommends" ] && ptx_debug "[hostname check] no hostname recommendation defined"
+ for hostname in $dependency_check_hostname_recommends; do
+ [ "`hostname`" = "$hostname" ] >/dev/null 2>&1
+ case $? in
+ 0)
+ ptx_debug "[hostname check] This Script recommends host $hostname: OK"
+ ;;
+ *)
+ ptx_warning "[hostname check] This Script recommends host $hostname: THIS IS NOT ME"
+ ;;
+ esac
+ done
+ [ -z "$dependency_check_hostname_depends" ] && ptx_debug "[hostname check] no hostname dependency defined"
+ for hostname in $dependency_check_hostname_depends; do
+ [ "`hostname`" = "$hostname" ] >/dev/null 2>&1
+ case $? in
+ 0)
+ ptx_debug "[hostname check] This Script depends on host $hostname: OK"
+ ;;
+ *)
+ ptx_bailout "[hostname check] This Script depends on host $hostname: THIS IS NOT ME"
+ ;;
+ esac
+ done
+ [ -z "$dependency_check_hostname_conflicts" ] && ptx_debug "[hostname check] no hostname conflict defined"
+ for hostname in $dependency_check_hostname_conflicts; do
+ [ "`hostname`" = "$hostname" ] >/dev/null 2>&1
+ case $? in
+ 0)
+ ptx_bailout "[hostname check] This Script conflicts with host $hostname: CONFLICT FOUND"
+ ;;
+ *)
+ ptx_debug "[hostname check] This Script conflicts with host $hostname: OK"
+ ;;
+ esac
+ done
+}
+
+#
+# convenience wrapper for the functions above
+#
+# performs all available checks
+#
+ptx_dependency_check(){
+ ptx_dependency_check_hostname
+ ptx_dependency_check_dirs
+ ptx_dependency_check_files
+ ptx_dependency_check_tools
+}
+
+# service specific lib functions, based on script domains:
+#
+# - dumb_tool
+# - tool
+# - development
+# - system_management
+#
+
+if [ -n "$PTX_SCRIPT_DOMAINS" ]; then
+for ptx_script_domain in $PTX_SCRIPT_DOMAINS; do
+ ptx_debug "loading config for domain: ${ptx_script_domain}"
+ SCONFS="$HOME/.ptxsd-${ptx_script_domain}.conf \
+ /usr/local/etc/ptxsd-${ptx_script_domain}.conf \
+ /etc/ptxsd-${ptx_script_domain}.conf \
+ `dirname $0`/ptxsd-${ptx_script_domain}.conf \
+ `dirname $0`/../lib/ptxsd-${ptx_script_domain}.conf"
+ for scriptconf in $SCONFS; do
+ if [ -e "$scriptconf" ] ; then
+ . $scriptconf && { ptx_debug "$scriptconf loaded"; break; }
+ fi
+ done
+ [ "$PTXSD" = "true" ] || ptx_warning " No valid Configuration for Domain: ${ptx_script_domain} found \
+ [ $conf (version $MY_VERSION) ] [ caller: $0 ]"
+done
+fi