diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-09-14 09:08:54 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-09-14 09:11:52 +0300 |
commit | dafed2c202a14986aa81144ebc8629266b366432 (patch) | |
tree | e6ece1c35e14d5494671caec8ab8a1db2451f88e | |
parent | 037518130f108dcfb302fe8d758c9f190e0304ba (diff) | |
download | rex-dafed2c202a14986aa81144ebc8629266b366432.tar.gz rex-dafed2c202a14986aa81144ebc8629266b366432.tar.bz2 |
Improve installer
* install: Install packages
* rc.tcl: Remove.
* rex.exp: Rename back to rex
* README: Update.
* README-hacking: Update.
-rwxr-xr-x | install | 195 | ||||
-rw-r--r-- | rc.tcl | 13 | ||||
-rwxr-xr-x | rex (renamed from rex.exp) | 0 |
3 files changed, 143 insertions, 65 deletions
@@ -22,31 +22,43 @@ package require Expect 5.44.1.15 # #################################################### set distfiles { - rex.exp { dst {$bindir/rex} - mode 0775 - sed {x { - global option - return [regsub {^(set sysconfdir[[:space:]]+).*} $x "\\1\"$option(sysconfdir)\""] - }} + rex { + dst {$bindir} + mode 0755 + sed {x { + global option + return [regsub {^(set sysconfdir[[:space:]]+).*} $x "\\1\"$option(sysconfdir)\""] + }} } - rex.man8 { dst {$mandir/man8/rex.8} - mode 0644 - sed {x { - global option - return [regsub {^(\.ds ET[[:space:]]+).*} $x "\\1$option(sysconfdir)"] - }} + rex.man8 { + dst {$mandir/man8} + newname rex.8 + mode 0644 + sed {x { + global option + return [regsub {^(\.ds ET[[:space:]]+).*} $x "\\1$option(sysconfdir)"] + }} + } + lib/entrustcard { + install { $optmodules } + files { entrustcard.tcl pkgIndex.tcl } + dst {$tclpackagedir/entrustcard1.0} + } + lib/vpnc { + install { $optmodules } + files { vpnc.tcl pkgIndex.tcl } + dst {$tclpackagedir/vpnc1.0} } COPYING { install 0 } README { install 0 } - entrustcard.tcl { install 0 } install { install 0 } - vpnc.exp { install 0 } } # #################################################### set verbose 0 set dry_run 0 set keep_going 0 +set optmodules 0 proc nextarg retvar { upvar $retvar ret @@ -77,7 +89,18 @@ proc mkdir_p dir { } } -# install [-sed PROC] [-mode MODE] FILE DEST +proc filelist {dir retvar} { + upvar $retvar l + foreach name [glob -nocomplain -directory $dir -types {f d} *] { + if [file isdirectory $name] { + readdir $name l + } else { + lappend l $name + } + } +} + +# install [-sed PROC] [-mode MODE] [-newname NAME] FILE ... DIR proc install args { global argv0 global keep_going @@ -93,40 +116,59 @@ proc install args { set mode [lindex $args 1] set args [lreplace $args 0 1] } + -newname { + set newname [lindex $args 1] + set args [lreplace $args 0 1] + } default { break } } } - if {[llength $args] != 2} { - return -code error "bad # args" + switch -- [llength $args] { + 0 - + 1 { return -code error "bad # args" } + 2 { } + default { + if [info exist newname] { + return -code error "-newname is meaningless with multiple files" + } + } } - set src [lindex $args 0] - set dst [lindex $args 1] + set destdir [lindex $args end] + mkdir_p $destdir - mkdir_p [file dirname $dst] - - if [info exists sedproc] { - set ichan [open $src "r"] - set ochan [open $dst "w" 0700] - while {[gets $ichan line] >= 0} { - puts $ochan [apply $sedproc $line] + foreach src [lreplace $args end end] { + if [info exist newname] { + set dst [file join $destdir $newname] + } else { + set dst [file join $destdir [file tail $src]] + } + + if [info exists sedproc] { + set ichan [open $src "r"] + set ochan [open $dst "w" 0700] + while {[gets $ichan line] >= 0} { + puts $ochan [apply $sedproc $line] + } + close $ichan + close $ochan + } else { + file copy -force -- $src $dst + } + if [info exists mode] { + file attributes $dst -permissions $mode + } else { + file attributes $dst -permissions \ + [file attributes $src -permissions] } - close $ichan - close $ochan - } else { - file copy -force -- $src $dst - } - if ![info exists mode] { - set mode [file attributes $src -permissions] } - file attributes $dst -permissions $mode } proc rexversion {} { - set chan [open rex.exp r] + set chan [open rex r] while {[gets $chan line] >= 0} { if {[regexp {^set version[[:space:]]+"([0-9\.]+)"} $line x ver]} { break @@ -136,6 +178,17 @@ proc rexversion {} { return $ver } +proc register_file {fname retvar} { + global argv0 + upvar $retvar filelist + if {[file exists $fname]} { + lappend filelist $fname + } else { + puts "$argv0: required file $fname does not exist" + exit 1 + } +} + proc distrib {} { global argv0 global distfiles @@ -148,11 +201,14 @@ proc distrib {} { for {set i 0} {$i < [llength $distfiles]} {incr i 2} { set fname [lindex $distfiles $i] - if {[file exists $fname]} { - lappend filelist $fname + unset -nocomplain directives + array set directives [lindex $distfiles [expr $i + 1]] + if [info exist directives(files)] { + foreach f $directives(files) { + register_file [file join $fname $f] filelist + } } else { - puts "$argv0: required file $fname does not exist" - exit 1 + register_file $fname filelist } } @@ -163,9 +219,7 @@ proc distrib {} { if {$verbose} { puts "running $command" } - try { - exec {*}$command - } trap CHILDSTATUS {results options} { + if [catch { exec {*}$command } results options] { puts stderr $results puts stderr "$argv0: tar exited with code [lindex [dict get $options -errorcode] 2]" catch {file delete $archive} @@ -180,7 +234,7 @@ array set option { mandir {$prefix/share/man} sysconfdir /etc/rex } -set options [join [array names option] {|}] +set options [join [concat [array names option] tclpackagedir] {|}] proc expandvar {input} { global option @@ -205,6 +259,9 @@ OPTIONS are: --sysconfdir=DIR set configuration directory (/etc/rex) --bindir=DIR set directory for user executables ($prefix/bin) --mandir=DIR set man documentation root directory ($prefix/share/man) + --tclpackagedir=DIR + directory for installing TCL packages + --extras install extra packages ENVAR=VALUE assigns VALUE to the environment variable ENVAR for install and all its subprocesses. @@ -229,6 +286,9 @@ while {[nextarg arg]} { {([[:alpha:]_][[:alnum:]_]+)=(.*)} { set env([lindex $opt 1]) [lindex $opt 2] } \ + {^--extras$} { + set optmodules 1 + } \ {^-h$} - \ {^--help$} { printhelp @@ -262,6 +322,19 @@ if {[info exists dist]} { exit 0 } +if {![info exist tclpackagedir]} { + set prefixlen [string length $option(prefix)] + foreach dir [lreverse $auto_path] { + if {[string equal -length $prefixlen $dir $option(prefix)]} { + set option(tclpackagedir) $dir + break + } + } + if {![info exist tclpackagedir]} { + set option(tclpackagedir) {$prefix/lib/rex} + } +} + if {[info exists env(DESTDIR)]} { regsub -- {/$} $env(DESTDIR) "" } else { @@ -275,28 +348,47 @@ foreach name [array names option] { while {[llength $distfiles] > 0} { incr numinst set src [lindex $distfiles 0] + unset -nocomplain directives array set directives [lindex $distfiles 1] set distfiles [lreplace $distfiles 0 1] - if {[info exists directives(install)] && !$directives(install)} { - continue + if {[info exists directives(install)]} { + if {![expr $directives(install)]} { + continue + } + unset directives(install) } - set dest [expandvar $directives(dst)] + set destdir "env(DESTDIR)[expandvar $directives(dst)]" unset directives(dst) + + if {[info exist directives(files)]} { +# set infiles [lmap fname $directives(files) {[file join $src $fname]}] + set infiles {} + foreach fname $directives(files) { + lappend infiles [file join $src $fname] + } + unset directives(files) + } elseif [file isdirectory $src] { +# filelist $src infiles + error "source directory is disallowed: $src" + } else { + set infiles [list $src] + } + set install_args {} foreach opt [array names directives] { lappend install_args "-$opt" $directives($opt) } + if {$verbose} { - puts "install $install_args $src $env(DESTDIR)$dest" + puts "install $install_args {*}$infiles $destdir" } if {!$dry_run} { - set dst "$env(DESTDIR)$dest" - if {[catch {install {*}$install_args $src $dst} res]} { - puts stderr "$argv0: error while installing $src to $dst: $res" + if {[catch {install {*}$install_args {*}$infiles $destdir} res]} { + puts stderr "$argv0: $res" if {$keep_going} { - lappend failures $dst + lappend failures $res } else { exit 1 } @@ -305,7 +397,6 @@ while {[llength $distfiles] > 0} { } if {[info exists failures]} { - puts stderr "$argv0: failed to install [llength $failures] out of $numinst files: [join $failures {, }]" exit 1 } @@ -1,13 +0,0 @@ -set config(path,lib) "LIBDIR" -set config(path,bin) "BINDIR" -set config(path,man) "MANDIR" - -## Set to the full pathname of the pidof(8) utility. -#set config(path,pidof) /sbin/pidof -## Set to the vpnc state directory -#set config(path,vpnc-state-dir) /var/run/vpnc -## Set to the directory where vpnc binaries reside -#set config(path,vpnc-sbin-dir) /usr/local/sbin -## If using Entrust card authentication, set this variable to the -## name of the directory where your card files are stored. -#set config(path,cards) $env(HOME)/etc/cards |