#! /ldcg/bin/wish # the next line restarts using wish \ # exec wish "$0" "$@" ## ******************************************************** ## ## This is the Laser Interferometer Gravitational ## Oservatory (LIGO) cntlmonSetup script. ## ## This script prompts user for ldasdb and ldasdbro ## information and set up the custom LDASdsnames.ini file ## for this site. ;#barecode ;## determine ldas or local client set mode local wm withdraw . wm protocol . WM_DELETE_WINDOW exit set TOPDIR /ldas_outgoing set auto_path "/ldas/lib $auto_path" set API cntlmon package require generic package require BWidget package provide cntlmonSetup 1.0 namespace eval cntlmonSetup { set dlgName .tmpDlg } ## ******************************************************** ## ## Name: cntlmonSetup::setAPIresource ## ## Description: ## extract ## ## Parameters: ## ## Usage: ## ## Comments ## proc cntlmonSetup::setAPIresource { rscfile patterns cmdlist } { set fd [ open $rscfile r ] set data [ read -nonewline $fd ] set data [ split $data \n ] close $fd set i 0 set rsctext "" set maxlen [ llength $patterns ] set found 0 foreach line $data { set idx 0 if { ! [ regexp {^[;#]+} $line ] } { if { $found < $maxlen } { foreach pat $patterns { if { [ regexp $pat $line ] } { set line [ lindex $cmdlist $idx ] incr found 1 break } else { incr idx 1 } } } } append rsctext $line\n } set fd [ open $rscfile w ] set rsctext [ string trim $rsctext \n ] puts $fd $rsctext close $fd } ## ******************************************************** ## ## Name: cntlmonSetup::dialog ## ## Description: ## extract ## ## Parameters: ## ## Usage: ## ## Comments ## proc cntlmonSetup::dialog {} { if { [ catch { catch { unset ::cntlmonSetup::wdialog } set dlg [Dialog $::cntlmonSetup::dlgName -parent . -modal local \ -separator 1 -title "cntlmonAPI keys: " \ -side bottom -default 0 -cancel 3 ] wm protocol $dlg WM_DELETE_WINDOW exit set bapply [$dlg add -name 0 -command "::cntlmonSetup::outFile $dlg" -text APPLY ] set bupdate [$dlg add -name 1 -command "::cntlmonSetup::clearDlg" -text RESET ] $dlg add -name cancel -command "destroy $dlg; exit" set dlgframe [$dlg getframe] label $dlg.lbl -text \ "Enter cntlmonAPI keys" \ -justify left -wrap 500 -relief raised pack $dlg.lbl -side top -expand 1 -fill x -padx 2 set i 0 set f [ frame $dlg.f -relief ridge -borderwidth 2 ] foreach key $::keys { set f2 [ frame $f.f2$key -relief ridge -borderwidth 2 ] LabelEntry $f2.${key}1 -label "$key key:" -labelwidth 20 -labelanchor w \ -textvariable ::cntlmonSetup::key1($key) -editable 1 -width 10 \ -helptext "$key public key" -show * LabelEntry $f2.${key}2 -label "$key key again:" -labelwidth 20 -labelanchor w \ -textvariable ::cntlmonSetup::key2($key) -editable 1 -width 10 \ -helptext "$key public key" -show * pack $f2.${key}1 $f2.${key}2 -side top -fill x -expand 1 -padx 3 -pady 1 pack $f2 -side top -fill x -expand 1 incr i 1 } LabelEntry $f.cmonclient -label "cmonClient installation:" -labelwidth 20 -labelanchor w \ -textvariable ::cntlmonSetup::cmonClient -editable 1 -width 10 \ -helptext "$key public key" pack $f.cmonclient -side top -fill x -expand 1 -padx 3 -pady 2 pack $f -side top -fill x -expand 1 set ::cntlmonSetup::cmonClient /ldas/lib/cmonClient label $dlg.fname -text \ "An updated copy of LDAScntlmon.rsc will be in /ldas_outgoing/cntlmonAPI \ when you hit the APPLY button.\nAn updated copy of cmonClient.rsc will be in your home directory." -wraplength 400 -justify left pack $dlg.fname -side top -fill x -expand 1 -padx 5 -pady 3 -anchor w wm protocol . WM_DELETE_WINDOW "destroy $dlg; exit" $dlg draw catch { destroy $++dlg } } err ] } { tk_messageBox -type ok -default ok \ -message $err -icon error } } ## ******************************************************** ## ## Name: cntlmonSetup::ckBlanks ## ## Description: ## extract ## ## Parameters: ## ## Usage: ## ## Comments ## proc cntlmonSetup::ckBlanks { tag field } { if { [ regexp {(?n)^\s*$} $field ] } { return -code error "$tag cannot be blanks !" } if { [ regexp {[\s\t\n]+} $field ] } { return -code error "$tag cannot have embedded blanks !" } } ## ******************************************************** ## ## Name: cntlmonSetup::validate ## ## Description: ## extract ## ## Parameters: ## ## Usage: ## ## Comments ## This proc exits if completed ok proc cntlmonSetup::validate {} { if { [ catch { foreach key $::keys { cntlmonSetup::ckBlanks "$key key" $::cntlmonSetup::key1($key) cntlmonSetup::ckBlanks "$key key" $::cntlmonSetup::key2($key) if { ! [ string equal $::cntlmonSetup::key1($key) $::cntlmonSetup::key2($key) ] } { return -code error "$key keys do not match" } } cntlmonSetup::ckBlanks "cmonClient installation" $::cntlmonSetup::cmonClient } err ] } { return -code error $err } } ## ******************************************************** ## ## Name: cntlmonSetup::outFile ## ## Description: ## extract ## ## Parameters: ## ## Usage: ## ## Comments ## This proc exits if completed ok proc cntlmonSetup::outFile { dlg } { if { [ catch { set patterns [ list ] set cmdlist [ list ] cntlmonSetup::validate lappend patterns "set ::CLIENTKEY" lappend cmdlist "set ::CLIENTKEY $::cntlmonSetup::key1(client)" lappend patterns "set ::CHALLENGE" lappend cmdlist "set ::CHALLENGE $::cntlmonSetup::key1(challenge)" set dir [ file join $::TOPDIR cntlmonAPI ] set cntlmonrsc [ file join $dir LDAScntlmon.rsc ] if { ! [ file exist $cntlmonrsc ] } { file copy [ file join /ldas lib cntlmonAPI LDAScntlmon.rsc ] $dir } else { file copy -force $cntlmonrsc $cntlmonrsc.bak } cntlmonSetup::setAPIresource $cntlmonrsc $patterns $cmdlist if { [ regexp {ldas/bin} $::cntlmonSetup::cmonClient ] } { set clientdir /ldas/lib/cmonClient } else { set clientdir $::cntlmonSetup::cmonClient } set localrsc [ file join $::env(HOME) cmonClient.rsc ] if { [ file exist $localrsc ] } { file copy -force $localrsc $localrsc.bak } else { file copy -force [ file join $clientdir cmonClient.rsc ] $localrsc } set patterns [ list ] set cmdlist [ list ] lappend patterns "set ::CHALLENGE" lappend cmdlist "set ::CHALLENGE $::cntlmonSetup::key1(challenge)" cntlmonSetup::setAPIresource $localrsc $patterns $cmdlist tk_messageBox -type ok -default "ok" \ -message "/ldas_outgoing/cntlmonAPI/LDAScntlmon.rsc \ and $::env(HOME)/cmonClient.rsc are updated." -icon info exit } err ] } { catch { close $fd } tk_messageBox -type ok -default "ok" \ -message $err -icon error } } ## ******************************************************** ## ## Name: cntlmonSetup::clearDlg ## ## Description: ## extract ## ## Parameters: ## ## Usage: ## ## Comments ## This proc exits if completed ok proc cntlmonSetup::clearDlg {} { foreach key $::keys { set ::cntlmonSetup::key1($user) "" set ::cntlmonSetup::key2($user) "" } set ::cntlmonSetup::cmonClient /ldas/lib/cmonClient } ## ******************************************************** ;## main line if { [ catch { set ::keys { client challenge } cntlmonSetup::dialog } err ] } { tk_messageBox -type ok -default "ok" \ -message $err -icon error exit }