home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / bin / ecryptfs-rewrite-file < prev    next >
Encoding:
Text File  |  2009-06-04  |  1.6 KB  |  62 lines

  1. #!/bin/sh -e
  2. #
  3. #    ecryptfs-rewrite-file
  4. #    Copyright (C) 2008 Canonical Ltd.
  5. #
  6. #    Authors: Dustin Kirkland <kirkland@canonical.com>
  7. #
  8. #    This program is free software: you can redistribute it and/or modify
  9. #    it under the terms of the GNU General Public License as published by
  10. #    the Free Software Foundation, version 2 of the License.
  11. #
  12. #    This program is distributed in the hope that it will be useful,
  13. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #    GNU General Public License for more details.
  16. #
  17. #    You should have received a copy of the GNU General Public License
  18. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  
  20. error() {
  21.     echo
  22.     echo "ERROR: $1" 1>&2
  23. }
  24. j=0
  25. for i in "$@"; do
  26.     [ "$i" = "." ] && continue
  27.     j=`expr $j + 1`
  28.     echo -n "INFO: Rewriting [$j/$#] [$i] ... "
  29.     opt=
  30.     if [ -d "$i" -a ! -h "$i" ]; then
  31.         # A directory, re-encrypt the filename
  32.         temp1=`mktemp -d "$i".XXXXXXXXXX` || {
  33.             error "Could not create tempdir"
  34.             continue
  35.         }
  36.         mv -f -T "$i" "$temp1" || {
  37.             error "Could not rename [$i] to [$temp1]"
  38.             rmdir "$temp1"
  39.             continue
  40.         }
  41.         mv -f "$temp1" "$i"    || {
  42.             error "Could not rename [$temp1] to [$i]"
  43.         }
  44.     else
  45.         # A file or symlink, re-encrypt the contents
  46.         temp1=`mktemp "$i".XXXXXXXXXX` || {
  47.             error "Could not create tempfile"
  48.             continue
  49.         }
  50.         cp -a "$i" "$temp1" || {
  51.             error "Could not copy [$i] to [$temp1]"
  52.             rm -f "$temp1"
  53.             continue
  54.         }
  55.         mv -f "$temp1" "$i" || {
  56.             error "Could not rename [$temp1] to [$i]"
  57.         }
  58.     fi
  59.     echo "[OK]"
  60. done
  61. exit 0
  62.