diff options
author | Jonas Smedegaard <dr@jones.dk> | 2008-07-29 02:27:27 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2008-07-29 02:27:27 +0200 |
commit | 5ccbda4c78df4db47033dc66938cb73284287cd4 (patch) | |
tree | c378ccd92645c68131e2901037414841dde53fc7 | |
parent | 862402018e7cad7d1098fa3f47bd686b46b3e7e0 (diff) |
localikiwikicreatesite: implemented interactive initial cleanup as needed.
-rwxr-xr-x | localikiwikicreatesite | 82 |
1 files changed, 80 insertions, 2 deletions
diff --git a/localikiwikicreatesite b/localikiwikicreatesite index 5602456..4da465d 100755 --- a/localikiwikicreatesite +++ b/localikiwikicreatesite @@ -11,8 +11,9 @@ # # TODO: Explicitly replace ~ with $HOME for shell use, and $ENV{'HOME'} for Perl # TODO: Quote variables everywhere -# TODO: Implement --verbose option -# TODO: Check for name collision and ask (except when --force is enabled) +# TODO: Implement --verbose and --quiet options (and fail if both are set) +# TODO: Implement --force option +# TODO: check for required helper commands (like make for originated sites) # set -e @@ -67,6 +68,20 @@ exit1() { exit 1 } +ask() { + echo -n "$1 (y/N)? " + read response + case "$response" in + y|Y) + : + ;; + *) + return 1 + ;; + esac + return +} + git_setenv_work() { set -e @@ -150,6 +165,69 @@ CFGDIR=~/private_webdata/$project DESTDIR=~/public_websites/$host DESTSRCDIR=~/public_websites/$srchost +# Create parent if missing / remove if already existing +# (eg. leave out SRCDIR if subdir of CFGDIR) +mkdirchildlist="CFGDIR DESTDIR DESTSRCDIR" +rmdirlist="CFGDIR DESTDIR DESTSRCDIR" + +mkdirchildfoundlist='' +for item in $mkdirchildlist; do + eval "childdir=\"\$$item\"" + parentdir="`dirname "$childdir"`" + if [ ! -d "$parentdir" ]; then + eval "mkdirchild_$item='(will create parent dir)'" + mkdirchildfoundlist="$mkdirchildfoundlist $item" + fi +done + +rmdirfoundlist='' +for item in $rmdirlist; do + eval "dir=\"\$$item\"" + if [ -d "$dir" ]; then + eval "rmdir_$item='(will replace existing!)'" + rmdirfoundlist="$rmdirfoundlist $item" + fi +done + +if [ "$quiet" != 'yes' ]; then + cat <<EOF +You chose to make an iki site with the following settings: + +Project: $project +Host: $host +Sourcehost: $srchost + +The following directories will be added to your system: + +Project dir: $CFGDIR $rmdir_CFGDIR$mkdir_CFGDIR +Content dir: $SRCDIR $rmdir_SRCDIR$mkdir_SRCDIR +Central Git: $DESTSRCDIR $rmdir_DESTSRCDIR$mkdir_DESTSRCDIR +Website dir: $DESTDIR $rmdir_DESTDIR$mkdir_DESTDIR + +EOF +fi + +if [ -n "$mkdirchildfoundlist$rmdirfoundlist" ] || [ "$verbose" = 'yes' ]; then + [ "$force" = 'yes' ] \ + || ask 'Continue' \ + || exit1 "User aborted (no changes made)" +fi + +for item in $mkdirchildfoundlist; do + eval "childdir=\"\$$item\"" + parentdir="`dirname "$childdir"`" + if [ ! -d "$parentdir" ]; then + mkdir -p "$parentdir" + fi +done + +for item in $rmdirfoundlist; do + eval "dir=\"\$$item\"" + if [ -d "$dir" ]; then + rm -rf "$dir" + fi +done + ## Init public RCS repositories git_init_pub "$project" git_init_pub "${project}_content" |