Commit b42b1b9d authored by Kirk Webb's avatar Kirk Webb

Restructure command file, rework variable substitution, fix bugs

Have the basecmds-phase2.af script use variables.  Much easier to read and
modify.  Also rework variable substitution as it's useful for this to occur
anywhere in the argument string.
parent ff92087f
......@@ -53,6 +53,7 @@ log Enabling Remote Desktop Protocol connections
addreg HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server ;; fDenyTSConnections ;; Dword ;; 0
# Change the manual peer list if necessary / desired.
# XXX: Ugh... Something still doesn't work here.
log Setting up the clock
addreg HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation ;; RealTimeIsUniversal ;; Dword ;; 1
runcmd w32tm.exe ;; /register
......
# Where to put the Cygwin source bits.
defvar swdir ;; C:\Software\Cygwin
# Where to fetch the Cygwin sources
defvar cyg_mirror ;; http://mirror.emulab.net/cygwin
# The name of the Cygwin setup executable.
defvar setup_exec ;; setup.exe
# Remote path to the Cygwin setup executable.
defvar setup_remote ;; %cyg_mirror%/%setup_exec%
# Local path for the Cygwin setup executable.
defvar setup_loc ;; %swdir%\%setup_exec%
# The list of Cygwin packages to install.
defvar cyg_pkgs ;; boost-devel,bison,byacc,cygrunsrv,flex,gawk,gcc4,g++4,inetutils,make,openssh,openssl-devel,perl,psmisc,python,shutdown,swig,sysvinit,tcsh,util-linux,w32api,bc,cvs,ed,emacs,file,gdb,git,nano,nc,patch,rcs,rpm,rsync,rxvt,subversion,vim,wget,unzip,zip
# Get cygwin user password
readvar sshpass
log Downloading Cygwin setup executable.
mkdir C:\Software\Cygwin
getfile http://mirror.emulab.net/cygwin/setup.exe ;; C:\Software\Cygwin\setup.exe
mkdir %swdir%
getfile %setup_remote% ;; %setup_loc%
log Running Cygwin installer.
runcmd C:\Software\Cygwin\setup.exe ;; -l C:\Software\Cygwin -s http://mirror.emulab.net/cygwin -O -R C:\Cygwin -q -P boost,bison,byacc,cygrunsrv,flex,gawk,gcc4,g++4,inetutils,make,openssh,openssl-devel,perl,psmisc,python,shutdown,swig,sysvinit,tcsh,util-linux,w32api,bc,cvs,ed,emacs,file,gdb,git,nano,nc,patch,rcs,rpm,rsync,rxvt,subversion,vim,wget,unzip,zip
runcmd %swdir%\setup.exe ;; -l %swdir% -s %cyg_mirror% -O -R C:\Cygwin -q -P %cyg_pkgs%
log Cygwin Setup Complete.
log Setting up syslogd
......@@ -11,7 +28,7 @@ runcyg syslogd-config -y ;; 0
log Setting up sshd
mkdir C:\Cygwin\etc\sshkeys
runcyg ssh-host-config -y -u cyg_sshd -w cYgw1n$$h -c '' --privileged ;; 0
runcyg ssh-host-config -y -u cyg_sshd -w %sshpass% -c '' --privileged ;; 0
runcyg sed -e 's|^AuthorizedKeysFile.*$|AuthorizedKeysFile /sshkeys/%u/authorized_keys|' /etc/sshd_config > /etc/sshd_config.new ;; 0
runcyg mv -f /etc/sshd_config.new /etc/sshd_config ;; 0
mkdir C:\Cygwin\etc\ssh
......
......@@ -59,21 +59,13 @@ Function isNumeric ($x) {
return $isNum
}
Function replace_uservars([ref]$cmdarr) {
for ($i=0; $i < $cmdarr.count; $i++) {
if ($cmdarr[$i] -match "^%($VAR_RE)%$") {
$vartok = $matches[1]
if ($uservars.ContainsKey($vartok)) {
$cmdarr[$i] = `
$uservars.Get_Item($vartok)
} else {
log("ERROR: Undefined variable referenced: $vartok")
log("Exiting!")
exit 1
}
}
Function replace_uservars($cmdstr) {
$uservars.getenumerator() | % {
$key = $_.key
$value = $_.value
$cmdstr = [regex]::Replace($cmdstr, "%$key%", $value)
}
return $cmdstr
}
#
......@@ -389,9 +381,8 @@ foreach ($cmdline in (Get-Content -Path $actionfile)) {
$cmdarr = @()
if ($argtoks) {
$cmdargs = [string]::join(" ", $argtoks)
#$cmdargs = [regex]::replace($cmdargs,',','`,')
$cmdargs = replace_uservars($cmdargs)
$cmdarr = [regex]::split($cmdargs, '\s*;;\s*')
replace_uservars([ref]$cmdarr)
}
$result = $FAIL
# XXX: Maybe refactor all of this with OOP at some point.
......@@ -423,6 +414,12 @@ foreach ($cmdline in (Get-Content -Path $actionfile)) {
"waitproc" {
$result = waitproc_func($cmdarr)
}
"defvar" {
$result = defvar_func($cmdarr)
}
"readvar" {
$result = readvar_func($cmdarr)
}
default {
log("WARNING: Skipping unknown action: $cmd")
$result = $SUCCESS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment