1;tor.nsi - A basic win32 installer for Tor
2; Originally written by J Doe.
3; Modified by Steve Topletz, Andrew Lewman
4; See the Tor LICENSE for licensing information
5;-----------------------------------------
6;
7!include "MUI.nsh"
8!include "LogicLib.nsh"
9!include "FileFunc.nsh"
10!insertmacro GetParameters
11!define VERSION "0.4.6.8"
12!define INSTALLER "tor-${VERSION}-win32.exe"
13!define WEBSITE "https://www.torproject.org/"
14!define LICENSE "LICENSE"
15!define BIN "..\bin" ;BIN is where it expects to find tor.exe, tor-resolve.exe
16
17
18SetCompressor /SOLID LZMA ;Tighter compression
19RequestExecutionLevel user ;Updated for Vista compatibility
20OutFile ${INSTALLER}
21InstallDir $PROGRAMFILES\Tor
22SetOverWrite ifnewer
23Name "Tor"
24Caption "Tor ${VERSION} Setup"
25BrandingText "The Onion Router"
26CRCCheck on
27XPStyle on
28VIProductVersion "${VERSION}"
29VIAddVersionKey "ProductName" "The Onion Router: Tor"
30VIAddVersionKey "Comments" "${WEBSITE}"
31VIAddVersionKey "LegalTrademarks" "Three line BSD"
32VIAddVersionKey "LegalCopyright" "�2004-2008, Roger Dingledine, Nick Mathewson. �2009 The Tor Project, Inc. "
33VIAddVersionKey "FileDescription" "Tor is an implementation of Onion Routing. You can read more at ${WEBSITE}"
34VIAddVersionKey "FileVersion" "${VERSION}"
35
36!define MUI_WELCOMEPAGE_TITLE "Welcome to the Tor Setup Wizard"
37!define MUI_WELCOMEPAGE_TEXT "This wizard will guide you through the installation of Tor ${VERSION}.\r\n\r\nIf you have previously installed Tor and it is currently running, please exit Tor first before continuing this installation.\r\n\r\n$_CLICK"
38!define MUI_ABORTWARNING
39!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\win-install.ico"
40!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\win-uninstall.ico"
41!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\win.bmp"
42!define MUI_FINISHPAGE_RUN "$INSTDIR\tor.exe"
43!define MUI_FINISHPAGE_LINK "Visit the Tor website for the latest updates."
44!define MUI_FINISHPAGE_LINK_LOCATION ${WEBSITE}
45
46!insertmacro MUI_PAGE_WELCOME
47; There's no point in having a clickthrough license: Our license adds
48; certain rights, but doesn't remove them.
49; !insertmacro MUI_PAGE_LICENSE "${LICENSE}"
50!insertmacro MUI_PAGE_COMPONENTS
51!insertmacro MUI_PAGE_DIRECTORY
52!insertmacro MUI_PAGE_INSTFILES
53!insertmacro MUI_PAGE_FINISH
54!insertmacro MUI_UNPAGE_WELCOME
55!insertmacro MUI_UNPAGE_CONFIRM
56!insertmacro MUI_UNPAGE_INSTFILES
57!insertmacro MUI_UNPAGE_FINISH
58!insertmacro MUI_LANGUAGE "English"
59
60Var CONFIGDIR
61Var CONFIGFILE
62
63Function .onInit
64	Call ParseCmdLine
65FunctionEnd
66
67;Sections
68;--------
69
70Section "Tor" Tor
71;Files that have to be installed for tor to run and that the user
72;cannot choose not to install
73	SectionIn RO
74	SetOutPath $INSTDIR
75	Call ExtractBinaries
76	Call ExtractIcon
77	WriteINIStr "$INSTDIR\Tor Website.url" "InternetShortcut" "URL" ${WEBSITE}
78
79	StrCpy $CONFIGFILE "torrc"
80	StrCpy $CONFIGDIR $APPDATA\Tor
81;   ;If $APPDATA isn't valid here (Early win95 releases with no updated
82;   ; shfolder.dll) then we put it in the program directory instead.
83;   StrCmp $APPDATA "" "" +2
84;      StrCpy $CONFIGDIR $INSTDIR
85	SetOutPath $CONFIGDIR
86	;If there's already a torrc config file, ask if they want to
87	;overwrite it with the new one.
88	${If} ${FileExists} "$CONFIGDIR\torrc"
89		MessageBox MB_ICONQUESTION|MB_YESNO "You already have a Tor config file.$\r$\nDo you want to overwrite it with the default sample config file?" IDYES Yes IDNO No
90		Yes:
91			Delete $CONFIGDIR\torrc
92			Goto Next
93		No:
94			StrCpy $CONFIGFILE "torrc.sample"
95		Next:
96	${EndIf}
97	File /oname=$CONFIGFILE "..\src\config\torrc.sample"
98
99; the geoip file needs to be included and stuffed into the right directory
100; otherwise tor is unhappy
101	SetOutPath $APPDATA\Tor
102	Call ExtractGEOIP
103SectionEnd
104
105Section "Documents" Docs
106	Call ExtractDocuments
107SectionEnd
108
109SubSection /e "Shortcuts" Shortcuts
110
111Section "Start Menu" StartMenu
112  SetOutPath $INSTDIR
113  ${If} ${FileExists} "$SMPROGRAMS\Tor\*.*"
114    RMDir /r "$SMPROGRAMS\Tor"
115  ${EndIf}
116  Call CreateTorLinks
117  ${If} ${FileExists} "$INSTDIR\Documents\*.*"
118    Call CreateDocLinks
119  ${EndIf}
120SectionEnd
121
122Section "Desktop" Desktop
123   SetOutPath $INSTDIR
124   CreateShortCut "$DESKTOP\Tor.lnk" "$INSTDIR\tor.exe" "" "$INSTDIR\tor.ico"
125SectionEnd
126
127Section /o "Run at startup" Startup
128   SetOutPath $INSTDIR
129   CreateShortCut "$SMSTARTUP\Tor.lnk" "$INSTDIR\tor.exe" "" "$INSTDIR\tor.ico" "" SW_SHOWMINIMIZED
130SectionEnd
131
132SubSectionEnd
133
134Section "Uninstall"
135   Call un.InstallPackage
136SectionEnd
137
138Section -End
139    WriteUninstaller "$INSTDIR\Uninstall.exe"
140    ;The registry entries simply add the Tor uninstaller to the Windows
141    ;uninstall list.
142    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Tor" "DisplayName" "Tor (remove only)"
143    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Tor" "UninstallString" '"$INSTDIR\Uninstall.exe"'
144SectionEnd
145
146!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
147!insertmacro MUI_DESCRIPTION_TEXT ${Tor} "The core executable and config files needed for Tor to run."
148!insertmacro MUI_DESCRIPTION_TEXT ${Docs} "Documentation about Tor."
149!insertmacro MUI_DESCRIPTION_TEXT ${ShortCuts} "Shortcuts to easily start Tor"
150!insertmacro MUI_DESCRIPTION_TEXT ${StartMenu} "Shortcuts to access Tor and its documentation from the Start Menu"
151!insertmacro MUI_DESCRIPTION_TEXT ${Desktop} "A shortcut to start Tor from the desktop"
152!insertmacro MUI_DESCRIPTION_TEXT ${Startup} "Launches Tor automatically at startup in a minimized window"
153!insertmacro MUI_FUNCTION_DESCRIPTION_END
154
155;####################Functions#########################
156
157Function ExtractBinaries
158	File "${BIN}\tor.exe"
159	File "${BIN}\tor-resolve.exe"
160FunctionEnd
161
162Function ExtractGEOIP
163	File "${BIN}\geoip"
164FunctionEnd
165
166Function ExtractIcon
167	File "${BIN}\tor.ico"
168FunctionEnd
169
170Function ExtractSpecs
171	File "..\doc\HACKING"
172	File "..\doc\spec\address-spec.txt"
173	File "..\doc\spec\bridges-spec.txt"
174	File "..\doc\spec\control-spec.txt"
175	File "..\doc\spec\dir-spec.txt"
176	File "..\doc\spec\path-spec.txt"
177	File "..\doc\spec\rend-spec.txt"
178	File "..\doc\spec\socks-extensions.txt"
179	File "..\doc\spec\tor-spec.txt"
180	File "..\doc\spec\version-spec.txt"
181FunctionEnd
182
183Function ExtractHTML
184	File "..\doc\tor.html"
185	File "..\doc\torify.html"
186	File "..\doc\tor-resolve.html"
187	File "..\doc\tor-gencert.html"
188FunctionEnd
189
190Function ExtractReleaseDocs
191	File "..\README"
192	File "..\ChangeLog"
193	File "..\LICENSE"
194FunctionEnd
195
196Function ExtractDocuments
197	SetOutPath "$INSTDIR\Documents"
198	Call ExtractSpecs
199	Call ExtractHTML
200	Call ExtractReleaseDocs
201FunctionEnd
202
203Function un.InstallFiles
204	Delete "$DESKTOP\Tor.lnk"
205	Delete "$INSTDIR\tor.exe"
206	Delete "$INSTDIR\tor-resolve.exe"
207	Delete "$INSTDIR\Tor Website.url"
208	Delete "$INSTDIR\torrc"
209	Delete "$INSTDIR\torrc.sample"
210	Delete "$INSTDIR\tor.ico"
211	Delete "$SMSTARTUP\Tor.lnk"
212	Delete "$INSTDIR\Uninstall.exe"
213    Delete "$INSTDIR\geoip"
214FunctionEnd
215
216Function un.InstallDirectories
217	${If} $CONFIGDIR == $INSTDIR
218		RMDir /r $CONFIGDIR
219	${EndIf}
220	RMDir /r "$INSTDIR\Documents"
221	RMDir $INSTDIR
222	RMDir /r "$SMPROGRAMS\Tor"
223	RMDir /r "$APPDATA\Tor"
224FunctionEnd
225
226Function un.WriteRegistry
227	DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Tor"
228FunctionEnd
229
230Function un.InstallPackage
231	Call un.InstallFiles
232	Call un.InstallDirectories
233	Call un.WriteRegistry
234FunctionEnd
235
236Function CreateTorLinks
237	CreateDirectory "$SMPROGRAMS\Tor"
238	CreateShortCut "$SMPROGRAMS\Tor\Tor.lnk" "$INSTDIR\tor.exe" "" "$INSTDIR\tor.ico"
239	CreateShortCut "$SMPROGRAMS\Tor\Torrc.lnk" "Notepad.exe" "$CONFIGDIR\torrc"
240	CreateShortCut "$SMPROGRAMS\Tor\Tor Website.lnk" "$INSTDIR\Tor Website.url"
241	CreateShortCut "$SMPROGRAMS\Tor\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
242FunctionEnd
243
244Function CreateDocLinks
245	CreateDirectory "$SMPROGRAMS\Tor\Documents"
246	CreateShortCut "$SMPROGRAMS\Tor\Documents\Tor Documentation.lnk" "$INSTDIR\Documents"
247	CreateShortCut "$SMPROGRAMS\Tor\Documents\Tor Specification.lnk" "$INSTDIR\Documents\tor-spec.txt"
248	CreateShortCut "$SMPROGRAMS\Tor\Documents\Tor Address Specification.lnk" "$INSTDIR\Documents\address-spec.txt"
249	CreateShortCut "$SMPROGRAMS\Tor\Documents\Tor Bridges Specification.lnk" "$INSTDIR\Documents\bridges-spec.txt"
250	CreateShortCut "$SMPROGRAMS\Tor\Documents\Tor Control Specification.lnk" "$INSTDIR\Documents\control-spec.txt"
251	CreateShortCut "$SMPROGRAMS\Tor\Documents\Tor Directory Specification.lnk" "$INSTDIR\Documents\dir-spec.txt"
252	CreateShortCut "$SMPROGRAMS\Tor\Documents\Tor Path Specification.lnk" "$INSTDIR\Documents\path-spec.txt"
253	CreateShortCut "$SMPROGRAMS\Tor\Documents\Tor Rend Specification.lnk" "$INSTDIR\Documents\rend-spec.txt"
254	CreateShortCut "$SMPROGRAMS\Tor\Documents\Tor Version Specification.lnk" "$INSTDIR\Documents\version-spec.txt"
255	CreateShortCut "$SMPROGRAMS\Tor\Documents\Tor SOCKS Extensions.lnk" "$INSTDIR\Documents\socks-extensions.txt"
256FunctionEnd
257
258Function ParseCmdLine
259	${GetParameters} $1
260	${If} $1 == "-x" ;Extract All Files
261		StrCpy $INSTDIR $EXEDIR
262		Call ExtractBinaries
263		Call ExtractDocuments
264		Quit
265	${ElseIf} $1 == "-b" ;Extract Binaries Only
266		StrCpy $INSTDIR $EXEDIR
267		Call ExtractBinaries
268		Quit
269	${ElseIf} $1 != ""
270		MessageBox MB_OK|MB_TOPMOST `${Installer} [-x|-b]$\r$\n$\r$\n  -x    Extract all files$\r$\n  -b    Extract binary files only`
271		Quit
272	${EndIf}
273FunctionEnd
274
275