]> Raphaël G. Git Repositories - youtubedl/blob - debian/patches/remove-autoupdate-mechanism.patch
d/p/remove-autoupdate-mechanism.patch: Update patch with metadata at the top.
[youtubedl] / debian / patches / remove-autoupdate-mechanism.patch
1 Subject: Remove autoupdate mechanism
2 Bug: 890119
3 Forwarded: no
4 From: Nicolas Braud-Santoni <nicolas@braud-santoni.eu>
5 Reviewed-by: Rogério Theodoro de Brito <rbrito@ime.usp.br>
6 Last-Update: 2018-03-16
7 Applied-Upstream: no
8
9 ---
10 youtube_dl/__init__.py | 8 ++-
11 youtube_dl/options.py | 2 +-
12 youtube_dl/update.py | 187 -------------------------------------------------
13 3 files changed, 6 insertions(+), 191 deletions(-)
14 delete mode 100644 youtube_dl/update.py
15
16 diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py
17 index ba684a0..298ed7e 100644
18
19 --- a/youtube_dl/__init__.py
20 +++ b/youtube_dl/__init__.py
21 @@ -36,7 +36,6 @@ from .utils import (
22 write_string,
23 render_table,
24 )
25 -from .update import update_self
26 from .downloader import (
27 FileDownloader,
28 )
29 @@ -432,7 +431,10 @@ def _real_main(argv=None):
30 with YoutubeDL(ydl_opts) as ydl:
31 # Update version
32 if opts.update_self:
33 - update_self(ydl.to_screen, opts.verbose, ydl._opener)
34 + parser.error(
35 + "youtube-dl's self-update mechanism is disabled on Debian.\n"
36 + "Please update youtube-dl using apt(8)."
37 + )
38
39 # Remove cache dir
40 if opts.rm_cachedir:
41 @@ -440,7 +442,7 @@ def _real_main(argv=None):
42
43 # Maybe do nothing
44 if (len(all_urls) < 1) and (opts.load_info_filename is None):
45 - if opts.update_self or opts.rm_cachedir:
46 + if opts.rm_cachedir:
47 sys.exit()
48
49 ydl.warn_if_short_id(sys.argv[1:] if argv is None else argv)
50 diff --git a/youtube_dl/options.py b/youtube_dl/options.py
51 index 4c04550..cca8cb6 100644
52 --- a/youtube_dl/options.py
53 +++ b/youtube_dl/options.py
54 @@ -140,7 +140,7 @@ def parseOpts(overrideArguments=None):
55 general.add_option(
56 '-U', '--update',
57 action='store_true', dest='update_self',
58 - help='Update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)')
59 + help=optparse.SUPPRESS_HELP)
60 general.add_option(
61 '-i', '--ignore-errors',
62 action='store_true', dest='ignoreerrors', default=False,
63 diff --git a/youtube_dl/update.py b/youtube_dl/update.py
64 deleted file mode 100644
65 index ebce966..0000000
66 --- a/youtube_dl/update.py
67 +++ /dev/null
68 @@ -1,187 +0,0 @@
69 -from __future__ import unicode_literals
70 -
71 -import io
72 -import json
73 -import traceback
74 -import hashlib
75 -import os
76 -import subprocess
77 -import sys
78 -from zipimport import zipimporter
79 -
80 -from .utils import encode_compat_str
81 -
82 -from .version import __version__
83 -
84 -
85 -def rsa_verify(message, signature, key):
86 - from hashlib import sha256
87 - assert isinstance(message, bytes)
88 - byte_size = (len(bin(key[0])) - 2 + 8 - 1) // 8
89 - signature = ('%x' % pow(int(signature, 16), key[1], key[0])).encode()
90 - signature = (byte_size * 2 - len(signature)) * b'0' + signature
91 - asn1 = b'3031300d060960864801650304020105000420'
92 - asn1 += sha256(message).hexdigest().encode()
93 - if byte_size < len(asn1) // 2 + 11:
94 - return False
95 - expected = b'0001' + (byte_size - len(asn1) // 2 - 3) * b'ff' + b'00' + asn1
96 - return expected == signature
97 -
98 -
99 -def update_self(to_screen, verbose, opener):
100 - """Update the program file with the latest version from the repository"""
101 -
102 - UPDATE_URL = 'https://rg3.github.io/youtube-dl/update/'
103 - VERSION_URL = UPDATE_URL + 'LATEST_VERSION'
104 - JSON_URL = UPDATE_URL + 'versions.json'
105 - UPDATES_RSA_KEY = (0x9d60ee4d8f805312fdb15a62f87b95bd66177b91df176765d13514a0f1754bcd2057295c5b6f1d35daa6742c3ffc9a82d3e118861c207995a8031e151d863c9927e304576bc80692bc8e094896fcf11b66f3e29e04e3a71e9a11558558acea1840aec37fc396fb6b65dc81a1c4144e03bd1c011de62e3f1357b327d08426fe93, 65537)
106 -
107 - if not isinstance(globals().get('__loader__'), zipimporter) and not hasattr(sys, 'frozen'):
108 - to_screen('It looks like you installed youtube-dl with a package manager, pip, setup.py or a tarball. Please use that to update.')
109 - return
110 -
111 - # Check if there is a new version
112 - try:
113 - newversion = opener.open(VERSION_URL).read().decode('utf-8').strip()
114 - except Exception:
115 - if verbose:
116 - to_screen(encode_compat_str(traceback.format_exc()))
117 - to_screen('ERROR: can\'t find the current version. Please try again later.')
118 - return
119 - if newversion == __version__:
120 - to_screen('youtube-dl is up-to-date (' + __version__ + ')')
121 - return
122 -
123 - # Download and check versions info
124 - try:
125 - versions_info = opener.open(JSON_URL).read().decode('utf-8')
126 - versions_info = json.loads(versions_info)
127 - except Exception:
128 - if verbose:
129 - to_screen(encode_compat_str(traceback.format_exc()))
130 - to_screen('ERROR: can\'t obtain versions info. Please try again later.')
131 - return
132 - if 'signature' not in versions_info:
133 - to_screen('ERROR: the versions file is not signed or corrupted. Aborting.')
134 - return
135 - signature = versions_info['signature']
136 - del versions_info['signature']
137 - if not rsa_verify(json.dumps(versions_info, sort_keys=True).encode('utf-8'), signature, UPDATES_RSA_KEY):
138 - to_screen('ERROR: the versions file signature is invalid. Aborting.')
139 - return
140 -
141 - version_id = versions_info['latest']
142 -
143 - def version_tuple(version_str):
144 - return tuple(map(int, version_str.split('.')))
145 - if version_tuple(__version__) >= version_tuple(version_id):
146 - to_screen('youtube-dl is up to date (%s)' % __version__)
147 - return
148 -
149 - to_screen('Updating to version ' + version_id + ' ...')
150 - version = versions_info['versions'][version_id]
151 -
152 - print_notes(to_screen, versions_info['versions'])
153 -
154 - # sys.executable is set to the full pathname of the exe-file for py2exe
155 - filename = sys.executable if hasattr(sys, 'frozen') else sys.argv[0]
156 -
157 - if not os.access(filename, os.W_OK):
158 - to_screen('ERROR: no write permissions on %s' % filename)
159 - return
160 -
161 - # Py2EXE
162 - if hasattr(sys, 'frozen'):
163 - exe = filename
164 - directory = os.path.dirname(exe)
165 - if not os.access(directory, os.W_OK):
166 - to_screen('ERROR: no write permissions on %s' % directory)
167 - return
168 -
169 - try:
170 - urlh = opener.open(version['exe'][0])
171 - newcontent = urlh.read()
172 - urlh.close()
173 - except (IOError, OSError):
174 - if verbose:
175 - to_screen(encode_compat_str(traceback.format_exc()))
176 - to_screen('ERROR: unable to download latest version')
177 - return
178 -
179 - newcontent_hash = hashlib.sha256(newcontent).hexdigest()
180 - if newcontent_hash != version['exe'][1]:
181 - to_screen('ERROR: the downloaded file hash does not match. Aborting.')
182 - return
183 -
184 - try:
185 - with open(exe + '.new', 'wb') as outf:
186 - outf.write(newcontent)
187 - except (IOError, OSError):
188 - if verbose:
189 - to_screen(encode_compat_str(traceback.format_exc()))
190 - to_screen('ERROR: unable to write the new version')
191 - return
192 -
193 - try:
194 - bat = os.path.join(directory, 'youtube-dl-updater.bat')
195 - with io.open(bat, 'w') as batfile:
196 - batfile.write('''
197 -@echo off
198 -echo Waiting for file handle to be closed ...
199 -ping 127.0.0.1 -n 5 -w 1000 > NUL
200 -move /Y "%s.new" "%s" > NUL
201 -echo Updated youtube-dl to version %s.
202 -start /b "" cmd /c del "%%~f0"&exit /b"
203 - \n''' % (exe, exe, version_id))
204 -
205 - subprocess.Popen([bat]) # Continues to run in the background
206 - return # Do not show premature success messages
207 - except (IOError, OSError):
208 - if verbose:
209 - to_screen(encode_compat_str(traceback.format_exc()))
210 - to_screen('ERROR: unable to overwrite current version')
211 - return
212 -
213 - # Zip unix package
214 - elif isinstance(globals().get('__loader__'), zipimporter):
215 - try:
216 - urlh = opener.open(version['bin'][0])
217 - newcontent = urlh.read()
218 - urlh.close()
219 - except (IOError, OSError):
220 - if verbose:
221 - to_screen(encode_compat_str(traceback.format_exc()))
222 - to_screen('ERROR: unable to download latest version')
223 - return
224 -
225 - newcontent_hash = hashlib.sha256(newcontent).hexdigest()
226 - if newcontent_hash != version['bin'][1]:
227 - to_screen('ERROR: the downloaded file hash does not match. Aborting.')
228 - return
229 -
230 - try:
231 - with open(filename, 'wb') as outf:
232 - outf.write(newcontent)
233 - except (IOError, OSError):
234 - if verbose:
235 - to_screen(encode_compat_str(traceback.format_exc()))
236 - to_screen('ERROR: unable to overwrite current version')
237 - return
238 -
239 - to_screen('Updated youtube-dl. Restart youtube-dl to use the new version.')
240 -
241 -
242 -def get_notes(versions, fromVersion):
243 - notes = []
244 - for v, vdata in sorted(versions.items()):
245 - if v > fromVersion:
246 - notes.extend(vdata.get('notes', []))
247 - return notes
248 -
249 -
250 -def print_notes(to_screen, versions, fromVersion=__version__):
251 - notes = get_notes(versions, fromVersion)
252 - if notes:
253 - to_screen('PLEASE NOTE:')
254 - for note in notes:
255 - to_screen(note)