Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / bin / cryptdir
CommitLineData
920dae64
AT
1#!/bin/sh
2# \
3exec expect -- "$0" ${1+"$@"}
4# Name: cryptdir
5# Author: Don Libes, NIST
6#
7# Synopsis:
8# cryptdir [dir]
9# decryptdir [dir]
10#
11# Encrypt or decrypts the current directory or named directory if given.
12
13if {[llength $argv] > 0} {
14 cd $argv
15}
16
17# encrypt or decrypt?
18set decrypt [regexp "decrypt" $argv0]
19
20set timeout -1
21stty -echo
22send "Password:"
23expect -re "(.*)\n"
24send "\n"
25set passwd $expect_out(1,string)
26
27# Wouldn't want to encrypt/decrypt files with mistyped password!
28send "Again:"
29expect -re "(.*)\n"
30send "\n"
31if {![string match $passwd $expect_out(1,string)]} {
32 send_user "mistyped password?\n"
33 stty echo
34 exit
35}
36stty echo
37
38log_user 0
39foreach f [glob *] {
40 # strip shell metachars from filename to avoid problems
41 if {[regsub -all {[]['`~<>:-]} $f "" newf]} {
42 exec mv $f $newf
43 set f $newf
44 }
45
46 set strcmp [string compare .crypt [file extension $f]]
47 if {$decrypt} {
48 # skip files that don't end with ".crypt"
49 if {0!=$strcmp} continue
50 spawn sh -c "exec crypt < $f > [file root $f]"
51 } else {
52 # skip files that already end with ".crypt"
53 if {0==$strcmp} continue
54 spawn sh -c "exec crypt < $f > $f.crypt"
55 }
56 expect "key:"
57 send "$passwd\r"
58 expect
59 wait
60 exec rm -f $f
61 send_tty "."
62}
63send_tty "\n"