#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
tacacsrc2gpg.py - Converts clear-text .tacacsrc to GPG-encrypted .tacacsrc.gpg

Intended for use when migrating from clear-text .tacacsrc to GPG.
"""

import os
import pwd
import socket
import sys

from trigger.tacacsrc import Tacacsrc, get_device_password, convert_tacacsrc
from trigger.utils.cli import yesno

if not yesno('This will overwrite your .tacacsrc.gpg and all gnupg configuration, are you sure?'):
    sys.exit(1)

(username, err, uid, gid, name, homedir, shell) = pwd.getpwuid(os.getuid())

print '''
======== [ READ ME READ ME READ ME READ ME ] ================
The following settings must be configured:

Real name: %s
Email Address: %s@%s
Comment: First Last
=============================================================
''' % (username, username, socket.getfqdn())

os.system('gpg --gen-key')

if yesno('Would you like to convert your OLD tacacsrc configuration file to your new one?')
        and os.path.isfile(homedir+'/.tacacsrc')
    convert_tacacsrc()
else:
    print "Old tacacsrc not converted."
    get_device_password()

@@ -360,21 +360,17 @@
 no%0A%0A
-if not yesno(
+prompt = 
 'Thi
@@ -448,16 +448,36 @@
 u sure?'
+%0Aif not yesno(prompt
 ):%0A    s
@@ -876,17 +876,18 @@
 ')%0A%0A
-if yesno(
+prompt2 = 
 'Wou
@@ -967,17 +967,26 @@
 ne?'
-)%0A       
+%0Aif yesno(prompt2)
  and
@@ -1005,18 +1005,31 @@
 ile(
+os.path.join(
 homedir
-+'/
+, '
 .tac
@@ -1035,16 +1035,18 @@
 cacsrc')
+):
 %0A    con

Fix typos in tools/tacacsrc2gpg.py that were causing it to fail.