Posted by hmontoliu Wed 28th Feb 2007 15:04 - Syntax is Bash - 54 views
Download | New Post | Modify | Hide line numbers
  1.  
  2. # TODO BLQ-0 (bug_report_lib.sh) VARIABLES GLOBALES
  3. BUGSQUAD_D=~/bugsquad_dir/
  4. LAUNCHPAD_BUG_URL="https://launchpad.net/distros/ubuntu/+source/ubiquity/+bug/" # >bugnum
  5. TMP_D=${BUGSQUAD_D}/tmp/
  6. CWD=$TMP_D
  7.  
  8.  
  9. bug_report_extract_crash_url () {
  10.     # Extrae la URL al crash_report(s) a partir del número de bug.
  11.     # Usage: -> bug_report_extract_crash_url "$BUGNUMBER"
  12.     # Input args:
  13.         local BUGNUMBER="$1" # numero de bug en Launchpad 
  14.     # Output: Crash Report(s) URL(s)
  15.     # Returns: 0 always
  16.     # Global Vars: $LAUNCHPAD_BUG_URL >> url de los informes de error
  17.         local LAUNCHPADBUGURL=$LAUNCHPAD_BUG_URL
  18.         local CRASH_REPORT_URL # Output: URL1 URL2 URL3
  19.  
  20.    
  21.     CRASH_REPORT_URL="$(wget -q -O - "$LAUNCHPAD_BUG_URL/$BUGNUMBER" | sed -n '/
    ">/,/<\div>/ {s@.*\(http://librarian.launchpad.net/.[^" ]*crash\)\".*@\1 @gp}')"
  22.     echo $CRASH_REPORT_URL
  23.     return 0;
  24. }
  25.  
  26.  
  27. bug_report_dwl_crash_file () {
  28.     # Baja el fichero "Crash Report" desde su URL.
  29.     # Usage: -> bug_report_dwl_crash_file "$CRASH_URL" "$DEST"
  30.     # Input args:
  31.         local CRASH_URL="$1" # Crash report file, URL, or - (stdin) 
  32.         local DEST="$2" # Destination (dir, filename, or - (stdout))
  33.     # Output: None
  34.     # Returns: 0 always
  35.    
  36.     # Distinguir entre nombre de fichero destino y directorio
  37.     if [ -d "$DEST" ]; then
  38.         cd "$DEST"; wget "$CRASH_URL"
  39.     else
  40.         # curl ?
  41.         wget -O "$DEST" "$CRASH_URL"
  42.     fi   
  43.  
  44.     return 0;
  45. }
  46.  
  47.  
  48. bug_report_dwl_short_crash_file () {
  49.     # Igual que bug_report_dwl_crash_file pero corta la descarga al llegar al
  50.     # coredump.
  51.     # Usage: -> bug_report_dwl_short_crash_file "$CRASH_URL" "$DEST"
  52.     # Input args:
  53.         local CRASH_URL="$1" #
  54.         local DEST="$2" #  
  55.     # Output: None
  56.     # Returns: 0 always
  57.         local TMPFILE WGETPID
  58.     TMPFILE=$(tempfile -p crashtmp)
  59.     WGETPIDFILE=$(tempfile -s pid)
  60.     # matamos a wget cuando empieze la descarga del coredump.
  61.     while :; do grep -q "Uname:" $TMPFILE && kill $(cat $WGETPIDFILE) && exit; sleep 1; done &
  62.     wget -O $TMPFILE $CRASH_URL & echo $! > $WGETPIDFILE
  63.     wait
  64.    # Salida a $DEST
  65.     if [ "$DEST" == "-" ]; then
  66.         sed -n '1,/^Uname:/ {p}' $TMPFILE
  67.     else
  68.         sed -n '1,/^Uname:/ {p}' $TMPFILE > "$DEST"
  69.     fi
  70.     # no es necesario 'ver man tmpfile', pero por si acaso:
  71.     [ -f "$TMPFILE" ] && rm -f "$TMPFILE"
  72.     [ -f "$WGETPIDFILE" ] && rm -f "$WGETPIDFILE"
  73.  
  74.     return 0;
  75. }
  76.  
  77.  
  78. bug_report_unpack () {
  79.     # Crea el directorio de destino y desempaqueta el fichero crash_file.
  80.     # Realmente no hay que hacer nada, apport-unpack se encarga de crear el
  81.     # directorio de destino.
  82.     # TODO: handle compressed files
  83.     # Usage: -> bug_report_unpack "$CRASH_FILE" "$DEST_CRASH_REPORT_DIR"
  84.     #        -> bug_report_unpack "-" "$DEST_CRASH_REPORT_DIR" # STDIN
  85.     # Input args:
  86.         local CRASH_FILE="$1" # Crash report file; "-" para stdin ;
  87.         local DEST_CRASH_REPORT_DIR="$2" # Dest dir to unpack crash report file
  88.     # Output: None
  89.     # Returns: 0 always
  90.    
  91.     # wget -O - "${CRASH_URL}" | apport-unpack - $CRASHDIR
  92.     apport-unpack $CRASH_FILE $DEST_CRASH_REPORT_DIR
  93.     return 0;
  94. }
  95.  
  96.  
  97. bug_report_summary () {
  98.     # Crea la cabecera del informe del error
  99.     # Usage: -> bug_report_summary "$CRASH_REPORT_DIR"
  100.     # Input args:
  101.         local CRASH_REPORT_DIR="$1" # Full path to bug report directory 
  102.     # Output: Bug Report Summary.
  103.     # Returns: 0 always
  104.    
  105.     local PACKAGE PACKAGE_VER DISTRO_RELEASE SOURCE_PACKAGE
  106.     PACKAGE="$(cat $CRASH_REPORT_DIR/Package)"
  107.     eval $(awk '{print "PACKAGE="$1" PACKAGE_VER="$2}' $CRASH_REPORT_DIR/Package)
  108.     DISTRO_RELEASE="$(cat $CRASH_REPORT_DIR/DistroRelease)"
  109.     SOURCE_PACKAGE="$(cat $CRASH_REPORT_DIR/SourcePackage)"
  110.  
  111.     cat <<- EOF
  112.     [Binary Package Hint: $PACKAGE]
  113.  
  114.     From the Attached Crash Report:
  115.     Distro Release: $DISTRO_RELEASE
  116.     Package (version): $PACKAGE ($PACKAGE_VER)
  117.     Source Package: $SOURCE_PACKAGE
  118.  
  119.     Original Description:
  120.     EOF
  121.     return 0;
  122. }
  123.  

PermaLink to this entry https://pastebin.co.uk/11166
Posted by hmontoliu Wed 28th Feb 2007 15:04 - Syntax is Bash - 54 views
Download | New Post | Modify | Hide line numbers

 

Comments: 0