forked from sigmaboy/nopaystation_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.sh
185 lines (169 loc) · 4.21 KB
/
functions.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
#!/bin/sh
ext="7z"
mime_type="application/x-7z-compressed"
sha256_choose() {
if which sha256 > /dev/null 2>&1
then
MY_BINARIES="${MY_BINARIES} sha256"
SHA256="sha256"
else
MY_BINARIES="${MY_BINARIES} sha256sum"
SHA256="sha256sum"
fi
}
my_sha256() {
local file="${1}"
case "$SHA256" in
"sha256sum")
sha256sum "${file}" | awk '{ print $1 }' ;;
"sha256")
sha256 "${file}" | awk '{ print $4 }' ;;
esac
}
downloader_choose() {
if which wget > /dev/null 2>&1
then
MY_BINARIES="${MY_BINARIES} wget"
DOWNLOADER="wget"
else
MY_BINARIES="${MY_BINARIES} curl"
DOWNLOADER="curl"
fi
}
my_download_file() {
local url="${1}"
local destination="${2}"
case "${DOWNLOADER}" in
"wget")
wget --no-verbose --show-progress -O "${destination}" "${url}" ;;
"curl")
curl --progress-bar -o "${destination}" "${url}" ;;
esac
}
check_binaries(){
local BINARIES="${1}"
for bins in ${BINARIES}
do
if ! which ${bins} > /dev/null 2>&1
then
echo "${bins} isn't installed."
echo "Please install it and try again"
exit 1
fi
done
}
region_rename() {
local NAME="${1}"
if echo "${NAME}" | grep -q "\[USA\]"
then
local NAME="$(echo "${NAME}" | sed 's/USA/NTSC/g')"
elif echo "${NAME}" | grep -q "\[JPN\]"
then
NAME="$(echo "${NAME}" | sed 's/JPN/NTSC-J/g')"
elif echo "${NAME}" | grep -q "\[EUR\]"
then
NAME="$(echo "${NAME}" | sed 's/EUR/PAL/g')"
elif echo "${NAME}" | grep -q "\[ASA\]"
then
NAME="$(echo "${NAME}" | sed 's/ASA/NTSC-C/g')"
fi
echo ${NAME}
}
check_valid_psv_id() {
local TITLE_ID="${1}"
if ! echo "${TITLE_ID}" | grep -q -E -i 'PCS[ABCDEFGH][0-9]{5}'
then
echo ""
echo "Error"
echo "Title ID is not valid."
echo "It should be the following format:"
echo "PCSA01234"
echo "Check your title id parameter."
exit 1
fi
}
check_valid_psm_id() {
local TITLE_ID="${1}"
if ! echo "${TITLE_ID}" | grep -q -E -i 'NP[NPOQ]A[0-9]{5}'
then
echo ""
echo "Error"
echo "Title ID is not valid."
echo "It should be the following format:"
echo "NPNA01234"
echo "Check your title id parameter."
exit 1
fi
}
check_valid_psp_id() {
local TITLE_ID="${1}"
if ! echo "${TITLE_ID}" | grep -q -E -i '[NU][PCL][UJEHA][DFGHJQSXZ][0-9]{5}'
then
echo ""
echo "Error"
echo "Title ID is not valid."
echo "It should be the following format:"
echo "NPUF00001"
echo "Check your title id parameter."
exit 1
fi
}
yesno_checksum() {
local GAME_ID="${1}"
while true
do
echo "Do you want to continue? (yes/no)"
read INPUT
case "${INPUT}" in
Yes|YES|yes|Y|y)
break
;;
No|NO|no|n)
echo "User aborted."
test -e "${GAME_ID}.pkg" && rm "${GAME_ID}.pkg"
if [ ${?} -eq 0 ]
then
echo "Downloaded file removed."
else
echo "Something went wrong while removing pkg file."
fi
exit 1
;;
esac
done
}
exit_if_fail() {
local _msg="${1}"
if [ "${?}" -ne 0 ]
then
echo "${_msg}"
exit 1
fi
}
check_announce_url() {
local URL="${1}"
echo "${URL}" | grep "^http" &> /dev/null
if [ ${?} -ne 0 ]
then
echo "No valid announce url provided. Be sure that the url starts with \"http\" and has a correct hostname"
exit 1
fi
}
compare_checksum(){
local LIST="${1}"
local FILE="${2}"
if [ -n "${LIST}" ]
then
if [ "${FILE}" != "${LIST}" ]
then
echo "Checksum of downloaded file does not match checksum in list"
echo "${FILE} != ${LIST}"
yesno_checksum
fi
else
echo "No checksum available in *.tsv list."
echo "Maybe you could report it:"
echo "\"${FILE}\""
echo ""
fi
}