8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
-
+
+
-
-
-
-
-
-
-
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
-
-
+
+
-
+
+
+
+
-
-
-
-
+
-
-
-
+
-
-
+
-
+
+
+
-
-
-
+
+
+
+
-
+
+
+
-
+
-
-
+
-
-
+
+
+
+
-
+
-
-
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
+
+
-
-
-
+
+
-
-
-
-
-
-
-
|
# - crafts streamtuner2 desktop shortcut
#
#>
[CmdletBinding()]
Param(
)
# admin check
function Test-IsElevated {
[CmdletBinding()]
param(
)
[Security.Principal.WindowsPrincipal] $Identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$Identity.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
if(!(Test-IsElevated)) {
Write-Host "If you run this script in non-elevated mode you will not be able to uninstall Python from control panel."
Write-Host ""
Write-Host "Do you want to proceed?"
$y = Read-Host "y/n"
if ($y -notmatch "y|Y|1") {
exit;
}
}
# default paths
$TEMP = $env:TEMP
$PYTHON = "C:\Python27"
$OutputEncoding = [System.Text.Encoding]::UTF8
#-- what
$files = @(
"https://www.python.org/ftp/python/2.7.12/python-2.7.12.msi#qb",
"http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.24/pygtk-all-in-one-2.24.2.win32-py2.7.msi#qbex",
"$PYTHON\Scripts\easy_install.exe requests",
"https://pypi.python.org/packages/3d/ee/affbc53073a951541b82a0ba2a70de266580c00f94dd768a60f125b04fca/lxml-2.3.win32-py2.7.exe",
"https://pypi.python.org/packages/62/71/8ac1f5c0251e51714d20e4b102710d5eee1683c916616129552b0a025ba5/pyquery-1.2.17-py2.py3-none-any.whl#noexec",
"$PYTHON\Scripts\pip.exe install $TEMP\pyquery-1.2.17-py2.py3-none-any.whl",
"http://effbot.org/downloads/PIL-1.1.7.win32-py2.7.exe"
)
#-- what and how to install
# each row is a list of (title,url,cmd,msi args,regkey)
$tasks = @(
@(
"Python 2.7.12", # title
"https://www.python.org/ftp/python/2.7.12/python-2.7.12.msi", # url
"", # custom cmd
"/qb", # msi args
"{9DA28CE5-0AA5-429E-86D8-686ED898C665}" # registry
),
@(
"PyGtk 2.24.2",
"http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.24/pygtk-all-in-one-2.24.2.win32-py2.7.msi",
"",
"TARGETDIR=C:\Python27 ADDLOCAL=ALL REMOVE=PythonExtensionModulePyGtkSourceview2,PythonExtensionModulePyGoocanvas,PythonExtensionModulePyRsvg,DevelopmentTools /qb",
"{09F82967-D26B-48AC-830E-33191EC177C8}"
),
@(
"Python requests",
"requests", # no download url, pip handles this
"pip",
"",
""
),
@(
"LXML 2.3",
"https://pypi.python.org/packages/3d/ee/affbc53073a951541b82a0ba2a70de266580c00f94dd768a60f125b04fca/lxml-2.3.win32-py2.7.exe",
"easy_install",
"",
""
),
@(
"PyQuery 1.2.1",
"https://pypi.python.org/packages/62/71/8ac1f5c0251e51714d20e4b102710d5eee1683c916616129552b0a025ba5/pyquery-1.2.17-py2.py3-none-any.whl",
"easy_install",
"",
""
),
@(
"PIL 1.1.7",
"http://effbot.org/downloads/PIL-1.1.7.win32-py2.7.exe",
"easy_install",
"",
""
)
)
# prepare registry lookup
$regPath = "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
if(!(Test-Path $regPath)) {
$regPath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
}
#-- ask before running
Write-Host ""
Write-Host "Do you want to install Python 2.7 and Gtk dependencies now?"
Write-Host "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
Write-Host " β This will install 32-bit versions of Python and Gtk."
Write-Host " β Leave the default install path of $PYTHON for this to work."
Write-Host " β Packages will go into $TEMP"
Write-Host " β Downloads will remain in $TEMP"
if(!(Test-IsElevated)) {
Write-Host -foregroundcolor red "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
Write-Host -foregroundcolor red "β β β If you run this script in non-elevated mode you will not be able to β"
Write-Host -foregroundcolor red "β uninstall Python and Gtk using the control panelsΒ΄ software list. β"
Write-Host -foregroundcolor red "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
}
Write-Host ""
$y = Read-Host "y/n"
if ($y -notmatch "y|Y|1") {
exit;
}
Write-Host ""
Write-Host "Downloading packages..."
#-- process
ForEach ($url in $files) {
ForEach ($task in $tasks) {
$title, $url, $cmd, $args, $regkey = $task;
echo "`n[[[ $url ]]]" #`
echo ""
echo "Installing $title"
echo "------------------------"
echo ""
chdir($TEMP);
$regPath = "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
if(!(Test-Path $regPath)) {
$regPath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
}
$regValueName = "WindowsInstaller"
$regValue = "0"
# get "filename" part from url
if ($url -match "https?://.+") {
$file = [regex]::match($url, "/([^/]+?)([\?\#]|$)").Groups[1].Value;
$file = [regex]::match($url, "/([^/]+?)([\?\#]|$)").Groups[1].Value;
# download
# download
if ($url -match "https?://.+") {
echo " β download( $url )"
$wget = New-Object System.Net.WebClient
$wget.DownloadFile($url, "$TEMP\$file");
# run
if ($url -match ".+#noexec") {
}
# run shorthand or custom command
if ($cmd) {
Write-Host "(skipping)"
chdir($PYTHON)
if ($cmd -eq "pip") {
$cmd = "$PYTHON\Scripts\pip.exe install $url"
}
elseif ($url -match ".+.msi#qb$") {
elseif ($cmd -match "^(easy|easy_install|silent)$") {
Write-Host "Installing Python 2.7.12 ..."
Start-Process -Wait msiexec -ArgumentList /i,"$TEMP\$file", " /qb"
$cmd = "$PYTHON\Scripts\easy_install.exe $TEMP\$file"
$registryPath = $regPath+"\{9DA28CE5-0AA5-429E-86D8-686ED898C665}"
Set-ItemProperty -Path $registryPath -Name $regValueName -Value $regValue
}
echo " β exec( $cmd )"
Invoke-Expression "& $cmd"
}
# msi
elseif ($url -match ".+.msi#qbex$") {
elseif ($file -match ".+.msi$") {
Write-Host "Installing PyGtk 2.24.2 ..."
Start-Process -Wait msiexec -ArgumentList /i,"$TEMP\$file", " TARGETDIR=C:\Python27 ADDLOCAL=ALL REMOVE=PythonExtensionModulePyGtkSourceview2,PythonExtensionModulePyGoocanvas,PythonExtensionModulePyRsvg,DevelopmentTools /qb"
echo " β exec( msiexec /i $file $args )"
Start-Process -Wait msiexec -ArgumentList /i,"$TEMP\$file",$args
$registryPath = $regPath+"\{09F82967-D26B-48AC-830E-33191EC177C8}"
Set-ItemProperty -Path $registryPath -Name $regValueName -Value $regValue
}
elseif ($url -match ".+.exe$") {
Start-Process -Wait "$TEMP\$file"
if ($regkey) { Try {
Set-ItemProperty -Path "$regPath\$regkey" -Name "WindowsInstaller" -Value "0"
} Catch {} }
}
# exe
elseif ($file -match ".+.exe$") {
echo " β exec( $file $args )"
if ($args) {
Start-Process -Wait "$TEMP\$file" -ArgumentList $args
}
else {
& "$TEMP\$file"
Start-Process -Wait "$TEMP\$file"
}
}
# other files
else {
# only run command
chdir($PYTHON)
Invoke-Expression "& $url"
echo " β exec( $file )"
& "$TEMP\$file"
}
}
#-- make ST2 .lnk
$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\Streamtuner2.lnk")
$Shortcut.TargetPath = "$PYTHON\pythonw.exe"
$Shortcut.Arguments = "c:\usr\bin\streamtuner2"
$Shortcut.Save()
function Test-IsElevated {
[CmdletBinding()]
param(
)
[Security.Principal.WindowsPrincipal] $Identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$Identity.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
|