Advertisement
Guest User

Untitled

a guest
May 5th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.02 KB | None | 0 0
  1. #!/bin/sh
  2. # Create a ramfs drive to store
  3. # secure password temporarily
  4. # Terribly Linux specific
  5.  
  6. targetdir=/tmp/ram_drive
  7. passfile=app_pass.txt
  8. my_user=$SUDO_USER
  9.  
  10. check_mount() {
  11.     if grep "$targetdir ramfs" /etc/mtab >/dev/null
  12.     then
  13.         # move on quietly.
  14.         :
  15.     else
  16.         mkdir -p $targetdir
  17.         mount -t ramfs none $targetdir
  18.         # Make sure its really there now
  19.         if grep "$targetdir ramfs" /etc/mtab >/dev/null
  20.         then
  21.             :
  22.         else
  23.             echo "$0: failed to mount ramdisk" 1>&2
  24.             exit 1
  25.         fi
  26.     fi
  27. }
  28. ask_for_ad_pass() {
  29.     if [ -f $targetdir/$passfile ];
  30.     then
  31.         # exit silently
  32.         exit 0;
  33.     fi
  34.     old_settings=$(stty -g)
  35.     stty -echo
  36.     echo -n "Password: "
  37.     read pass
  38.     echo $pass > $targetdir/$passfile
  39.     stty $old_settings
  40.     chown "${my_user}" $targetdir/$passfile
  41.     chmod 600 $targetdir/$passfile
  42.     echo
  43.     echo "Stored Password on RAM Drive"
  44. }
  45.  
  46. check_mount
  47. ask_for_pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement