1
(*
2
	Apple Script for starting, stopping and configuring the GPG-SMTP-Server
3
	
4
	The GPG-SMTP-Server is implemented in ruby. This Apple Script starts and
5
	stops the server enginge and allows to setup basic parameters as GPG 
6
	passphrase, SMTP account and passphrase, etc.
7
	
8
	(C) 2009, GNU General Public Licence, Author: Otto Linnemann
9
*)
10
11
# setup path to script folders 
12
set resourcesFolder to ((path to me) as string) & "Contents:Resources:"
13
set toolPath to (POSIX path of resourcesFolder)
14
15
# check for existence of config file /Library/Preferences/GpgServer.plist
16
set UserName to do shell script "whoami"
17
set PathToConfigFile to "/Users/" & UserName & "/Library/Preferences/GpgServer.plist"
18
set PathToDefaultConfigFile to toolPath & "GpgServer.plist"
19
20
try
21
	do shell script "/bin/ls " & PathToConfigFile
22
on error errMsg number errNum
23
	do shell script "/bin/cp " & PathToDefaultConfigFile & " " & PathToConfigFile
24
	display dialog "You need to configure the Filter Server first"
25
	tell application "Property List Editor" to open PathToConfigFile
26
end try
27
28
29
# Passphrase dialog
30
set done to false
31
set Input to display dialog "GPG-SMPT-Server
32
Please enter your password for your secret key:" with title "GPG-Password" with icon caution default answer "" buttons {"Cancel", "OK"} default button 2 giving up after 295 with hidden answer
33
34
set passphrase to text returned of Input as string
35
try
36
	do shell script "ruby " & "-C " & toolPath & " gpg_check_passphrase.rb  " & passphrase
37
on error
38
	display dialog "Wrong GPG Passphrase"
39
	set done to true
40
end try
41
42
43
# Start/Restart Loop
44
repeat until done = true
45
	
46
	do shell script "ruby " & "-C " & toolPath & " gpg_smtp_server.rb  " & passphrase & " " & PathToConfigFile & " > /dev/null 2>&1 & echo $!"
47
	set pid to the result
48
	display dialog "GPG-SMTP-Server is running, process ID is " & pid as string buttons {"Restart", "Stop", "Reconfigure"} with icon alias ((path to me) & "Contents:Resources:running.icns" as string)
49
	
50
	if button returned of result = "Stop" then
51
		set done to true
52
	else if button returned of result = "Reconfigure" then
53
		tell application "Property List Editor" to open PathToConfigFile
54
	end if
55
	
56
	do shell script "kill " & pid
57
	
58
end repeat