-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-makemkv-key.sh
189 lines (162 loc) · 6.88 KB
/
get-makemkv-key.sh
1
2
3
4
5
6
7
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/sh
scriptversion="trunk"
scriptlastedit="20200620"
scriptauthor="John Pyper"
scriptsite="https://github.com/jpyper/bash-scripts"
#################
### [ ABOUT ] ###
#################
# -=[ MAKEMKV BETA REGISTRATION KEY RETRIEVER ]=-
#
# Quick script to get the most current MakeMKV registration key while it is still in beta (forever?).
#
# MakeMKV seems to be in a forever free beta (but that could change at any time), I highly recommend
# purchasing a lifetime registration code for the reasonably valued cost of $50 USD.
# https://www.makemkv.com/buy/
#####################################################################################################
########################
### [ USER OPTIONS ] ###
########################
# url to forum post where makemkv key is posted, official from the developer.
# please don't change this setting. if the url does change, i will update the script and push a new version out.
keypage="https://www.makemkv.com/forum/viewtopic.php?f=5&t=1053"
# full path to place temporary keypage file
keypagetmp="/tmp/.keypage"
# where is the 'curl' binary
curlbin="curl"
# where is the 'grep' binary
grepbin="grep"
# where is the 'sed' binary
sedbin="sed"
# where is the 'rm' binary
rmbin="rm"
#####################################################################################################
#####################
### [ CHANGELOG ] ###
#####################
# 20200620:
# - removed BASH 'type -P' callouts to find dependencies
# ~ changed default USER OPTIONS for binaries to blindly point to their name
# + added 'rm' as a dependency
# + now using a temp file to locally cache the remote page and remove it when done ... seems to be a dirty necessity
# + add check to make sure keypagetmp file downloaded
# + add check for keypagetmp file and remove it when finished
# + added a simple sub-shell call to test for each dependency binary version, just looking for a reply
# = don't assume dependencies are installed in base (but they should be)
# = according to "shellcheck -s sh get-makemkv-key.sh", this script does not contain any suggestions/errors/breaks
# + that should make this script fully POSIX compliant
# 20200617:
# ~ changed shebang at top of script from "/usr/bin/env bash" to "/bin/sh" for more compatibility
# ~ changed double brackets to single brackets in if statements for POSIX compliance
# + added a couple of double quotes around a few variables for POSIX compliance
# + added ${keypage} to the ${makemkv_key_forum_post} because I forgot I had the actual url in there...oops
# - removed BASH version check, since script no longer targets BASH for its shell
# 20200616:
# - removed occurances of using 'which' to find commands
# + use BASH's built-in 'type -P' to find commands faster
# + add BASH version check to DEPENDENCIES CHECK section
# + add MIT license
# + add this CHANGELOG section
# 20200615:
# + initial release
#####################################################################################################
###################
### [ LICENSE ] ###
###################
# This script is licensed under the MIT License.
# Details here: http://opensource.org/licenses/MIT
#####################################################################################################
##############################
### [ DEPENDENCIES CHECK ] ###
##############################
# check for 'curl' binary
curltest="$(${curlbin} --version)"
if [ "${curltest}" = "" ]; then
echo "[E]: curl binary not found."
echo "[E]: the 'curlbin' variable at the top of this script"
echo "[E]: points to: ${curlbin}"
echo
echo "Check your package manager for 'curl' and install it, or"
echo "set the proper path in the 'curlbin' variable."
exit
fi
# check for 'grep' binary
greptest="$(${grepbin} --version)"
if [ "${greptest}" = "" ]; then
echo "[E]: grep binary not found."
echo "[E]: the 'grepbin' variable at the top of this script"
echo "[E]: points to: ${grepbin}"
echo
echo "Check your package manager for 'grep' and install it, or"
echo "set the proper path in the 'grepbin' variable."
exit
fi
# check for 'sed' binary
sedtest="$(${sedbin} --version)"
if [ "${sedtest}" = "" ]; then
echo "[E]: sed binary not found."
echo "[E]: the 'sedbin' variable at the top of this script"
echo "[E]: points to: ${sedbin}"
echo
echo "Check your package manager for 'sed' and install it, or"
echo "set the proper path in the 'sedbin' variable."
exit
fi
# check for 'rm' binary
rmtest="$(${rmbin} --version)"
if [ "${rmtest}" = "" ]; then
echo "[E]: rm binary not found."
echo "[E]: the 'rmbin' variable at the top of this script"
echo "[E]: points to: ${rmbin}"
echo
echo "Check your package manager for 'coreutils' and install it, or"
echo "set the proper path in the 'rmbin' variable."
exit
fi
#####################################################################################################
#############################
### [ DO THE DIRTY WORK ] ###
#############################
# let's start with a blank screen
clear
# display script header
echo "+-----------------------------------------------"
echo "| MakeMKV Beta Registration Key Retriever"
echo "| version: ${scriptversion} (${scriptlastedit})"
echo "| by: ${scriptauthor}"
echo "| web: ${scriptsite}"
echo "+-----------------------------------------------"
echo
echo "MakeMKV is free while in beta, and has been for a VERY long time."
echo
echo "Info extracted from forum post: https://www.makemkv.com/forum/viewtopic.php?f=5&t=1053"
echo
echo "---------------------------------------------------------------------------------------"
# get page contents and store it all in a variable (no external files needed)
${curlbin} --silent "${keypage}" -o "${keypagetmp}"
# make sure key page was downloaded (or at least _SOMETHING_ was downloaded)
if [ ! -f "${keypagetmp}" ]; then
echo "[E]: The temporary page can not be found."
echo "[E]: The 'keypagetmp' variable at the top of this script"
echo "[E]: points to: ${keypagetmp}"
echo
echo "Make sure the directory in the 'keypagetmp' variable is writable by the user running this script."
echo "There is also a possibility that the page could not be retrieved. No network. Page moved (doubtful),"
echo "or some other error from 'curl'."
exit
fi
# weed out the registration code and save it in a variable
makemkv_reg_key="$(${grepbin} "code>T-" "${keypagetmp}" | ${sedbin} -e 's/.*<pre><code>//' -e 's/<.*$//')"
# display registration code
echo "Registration code: ${makemkv_reg_key}"
# weed out the expiration date and save it in a variable
makemkv_reg_date="$(${grepbin} "valid until" "${keypagetmp}" | ${sedbin} -e 's/^.*valid until //' -e 's/\..*$//')"
# display expiration date
echo " Code Valid Until: ${makemkv_reg_date}"
echo "---------------------------------------------------------------------------------------"
# remove temporary file
if [ -f "${keypagetmp}" ]; then
${rmbin} "${keypagetmp}"
fi
# print extra line for cleanliness
echo