diff options
Diffstat (limited to 'install.awk')
| -rw-r--r-- | install.awk | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/install.awk b/install.awk new file mode 100644 index 0000000..78c9f94 --- /dev/null +++ b/install.awk @@ -0,0 +1,64 @@ +function path_join(a, b, x, y) { + x = a + y = b + + sub(/\/+$/, "", x) # remove trailing / from a + sub(/^\/+/, "", y) # remove leading / from b + + if (x == "") + return y + if (y == "") + return x + + return x "/" y +} + +BEGIN { FS = "," } ; +ARGIND == 1 { + # requested dirs + dir=path_join(ENVIRON["HOME"], $1) + cmd="mkdir -p " dir + print cmd + system(cmd) + + next +} + +ARGIND == 2 { + # block for locations + src=path_join(ENVIRON["PWD"], $1) + dst=path_join(ENVIRON["HOME"], $2) + testcmd="test -e " dst + linkcmd="ln -sf " src " " dst + diffcmd="diff -ursN " dst " " src + + if (system(testcmd) == 0) { + system("ls -lda " dst) + printf "Exists, overwrite? y/N/d" # no newline + getline resp < "/dev/tty" + while (1) { + if (resp == "d" || resp == "D") { + # dst is exists src is new, order is right + print "Showing diff to apply (empty is none)" + system(diffcmd) + printf "Exists, overwrite? y/N/d" # no newline + getline resp < "/dev/tty" + continue + } else if (resp == "y" || resp == "Y") { + print linkcmd + system(linkcmd) + break + } else if (resp == "n" || resp == "N" || resp == "") { + print "Skipped" + break + } + print "Exists, overwrite? y/N/d" + getline resp < "/dev/tty" + } + } else { + print linkcmd + system(echo linkcmd) + } +} + + |
