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