Reply To: How to delete site?

Clovertech Forums Cloverleaf How to delete site? Reply To: How to delete site?

#114833
Charlie Bursell
Participant

    STILL would not let me upload!  So here is script.

    !/usr/bin/env tcl

    # This script will prompt for a site name then remove that site directory and
    # remove the site from the server.ini file.

    # The user must have read/write permissions to the site directory and all of
    # the files within or the site delete will fail.

    proc main {argv argc} {

    global env argv0 tcl_platform

    # The get the root path
    set root $env(HCIROOT)

    # The name of the procedure
    set myname [lindex [split [file tail $argv0] .] 0]

    # Test for a single argument
    if {$argc != 1 || [string equal -nocase [lindex $argv 0] -h]} {
    puts stderr “\nUsage:\t$myname <sitename>\t Where:”
    puts stderr “\t sitename = Name of site to remove\n”
    exit -1
    }

    # Get site name
    set site [lindex $argv 0]

    # Validate that the site exists
    if {![file isdirectory [file join $root $site]]} {
    puts stderr “\n$myname: Site $site does not exist in $root\n”
    exit -1
    }

    # If not sure, bail out now!
    puts stdout “\n$myname: WARNING!! This is a very dangerous command!”
    puts -nonewline stdout “Site $site will be removed from $root. OK? \[n\] ”
    flush stdout
    gets stdin ans

    # If any response other than Y{es}, bail out
    if {![regexp -nocase {^Y} $ans]} {
    puts stdout “\n$myname: requested exit – done\n”
    exit
    }

    # Tell em what we are doing
    puts stdout “\n$argv – Attempting to remove $site directory from $root\n”

    # Attempt to remove the site directory
    if {[catch {file delete -force [file join $root $site]} err]} {
    puts stderr “\n$myname: Cannot remove site $site\n$err\n”
    exit -1
    }

    # Site directory was removed. Now remove site from server.ini

    # Path to server.ini file
    set svr [file join $root server server.ini]

    # A regsub pattern of the site to remove
    # Note that the entry will end with ; unless the last entry
    # + = 0 or 1 instances of the preceeding character
    set pat “[file join $root $site];?”

    # If on windows, use backslash
    if {[regexp -nocase — {^WIN} $tcl_platform(os)]} {
    regsub -all — {/} $pat {\\\\} pat
    }

    # Read the server.ini file
    if {[catch {read_file -nonewline $svr} inidata]} {
    puts stderr “\n$myname: Cannot open $svr – $inidata\n”
    exit -1
    }

    # regsub out the site entry

    if {![regsub — $pat $inidata {} inidata]} {
    puts stderr “\n$myname: $site not found in $svr file. $svr not changed\n”
    exit -1
    } else {

    # Write the modified server.ini file back
    if {[catch {write_file $svr $inidata} err]} {
    puts stderr “\n$myname: Cannot replace $svr – $err\n”
    exit -1
    }
    }

    # All done
    puts stdout “\n$myname: $site successfully removed\n”
    }

    main $argv $argc