This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Juako

By: a guest on Feb 26th, 2011  |  syntax: Bash  |  size: 1.56 KB  |  views: 136  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. # globals-------------------------------------------------------------------
  4. script_name="${0##*/}"
  5. script_dir=$(readlink -f "${0%/*}")
  6. script_version=1
  7.  
  8. # this can be modded to be supplied from command line
  9. named_dir='/var/named'
  10. serialfile="ufis-common.txt"
  11.  
  12. # main----------------------------------------------------------------------
  13. [[ "$1" ]] && {
  14.     (( ${#1} == 10 )) && newserial=$1
  15.     (( ${#1} == 8 )) && date=$1
  16.     (( ${#1} == 2 )) && revision=$1
  17.     ! [[ "$1" =~ ^[0-9]+$ ]] || [[ -z "$newserial$date$revision" ]] && echo "$script_name: ERROR: can't do anything with $1" && exit 1
  18. }  
  19.  
  20. curserial="$( sed -ne 's/^.*\([0-9]\{10\}\).*/\1/g; /^[0-9]*$/p' "$named_dir/$serialfile" )"
  21.  
  22. # if we haven't been passed a serial lets build one
  23. [[ -z "$newserial" ]] && {
  24. # if we don't have a date get current
  25.     [[ -z "$date" ]] && date="$(date +%Y%m%d)"
  26. # if we don't have revision number get next from the current, if current=99 or date<>today it'll be "01"
  27.     [[ -z "$contador" ]] && {
  28.         revision="01"
  29.         (( ${curserial:0:8} == $date )) && {
  30.             revision=$( printf "%02d" $(( 10#${curserial:8:2}+1 )) )
  31.             (( 10#$revision == 100 )) && echo "$script_name: warning: revision counter looped to 01" && revision="01"
  32.         }
  33.     }
  34.     newserial=$date$revision
  35. }
  36.  
  37. # replace the serial
  38. # some sanity checks here won't hurt
  39. # this is a minimal one
  40. (( ${#newserial} == 10 )) && {
  41.     echo "$script_name: new serial number $newserial"
  42.     sed -i "s/\(^.*\)$curserial\(.*$\)/\1$newserial\2/" "$named_dir/$serialfile"
  43. }
clone this paste RAW Paste Data