forked from sigmaboy/nopaystation_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nps_bundle.sh
executable file
·194 lines (174 loc) · 5.12 KB
/
nps_bundle.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
189
190
191
192
193
194
#!/bin/sh
# AUTHOR sigmaboy <[email protected]>
# get directory where the scripts are located
SCRIPT_DIR="$(dirname "$(readlink -f "$(which "${0}")")")"
# source shared functions
. "${SCRIPT_DIR}/functions.sh"
### usage function
my_usage(){
echo ""
echo "Parameters:"
echo "--nps-dir|-d <DIR> path to the directory containing the tsv files"
echo "--torrent|-c <ANNOUNCE URL> Enables torrent creation. Needs announce url"
echo "--source|-s <SOURCE TAG> Enables source flag. Needs source tag as argument"
echo "--all|-a Download all update instead of only latest"
echo ""
echo "The \"--source\" and \"--torrent\" parameter are optional. All other"
echo "parameters are required. The source parameter"
echo "is required for private torrent trackers only"
echo ""
echo "Usage:"
echo "${0} --nps-dir </path/to/nps/directory> [--torrent \"http://announce.url\"] [--source <SOURCE_TAG>]"
}
my_mktorrent(){
local TORRENT_SOURCE="${1}"
if [ "${SOURCE_ENABLE}" -eq 0 ]
then
mktorrent -dpa "${ANNOUNCE_URL}" "${TORRENT_SOURCE}"
else
mktorrent -dpa "${ANNOUNCE_URL}" -s "${SOURCE_TAG}" "${TORRENT_SOURCE}"
fi
}
### check if nps tsv file directory exists
test_nps_dir() {
local NPS_DIR="${1}"
if [ ! -d "${NPS_DIR}" ]
then
echo "Directory containing *.tsv files missing (\"${NPS_DIR}\"). Check your path parameter."
my_usage
exit 1
fi
}
SOURCE_ENABLE=0
CREATE_TORRENT=0
UPDATE_ALL=0
while [ ${#} -ge 1 ]
do
opt=${1}
shift
case ${opt} in
-t|--title-id)
test -n "${1}"
exit_if_fail "\"-t\" used without <TITLE ID>"
check_valid_psv_id "${1}"
TITLE_ID="${1}"
shift
;;
-c|--torrent)
test -n "${1}"
exit_if_fail "\"-c\" used without torrent announce URL"
check_announce_url "${1}"
ANNOUNCE_URL="${1}"
CREATE_TORRENT=1
shift
;;
-s|--source)
test -n "${1}"
exit_if_fail "\"-s\" used without source flag argument used"
SOURCE_TAG="${1}"
SOURCE_ENABLE=1
shift
;;
-d|--nps-dir)
test -n "${1}"
exit_if_fail "\"-d\" used without directory path argument used"
test_nps_dir "${1}"
NPS_DIR="${1}"
shift
;;
-a|--all)
UPDATE_ALL=1
shift
;;
*)
echo "Invalid parameter used."
my_usage
echo ""
exit 1
;;
esac
done
# check if necessary binaries are available
MY_BINARIES="pkg2zip sed"
if [ ${CREATE_TORRENT} -eq 1 ]
then
MY_BINARIES="${MY_BINARIES} mktorrent"
fi
check_binaries "${MY_BINARIES}"
if [ -z "${TITLE_ID}" ]
then
echo "ERROR:"
echo "<TITLE ID> is missing."
echo 'Use "-t <TITLE ID>" parameter'
exit 1
elif [ -z "${NPS_DIR}" ]
then
echo "ERROR:"
echo "<NPS DIR> is missing."
echo 'Use "-d <NPS DIR>" parameter'
exit 1
fi
### check if nps tsv file directory exists
if [ ! -d "${NPS_DIR}" ]
then
echo "Directory containing *.tsv files missing (\"${NPS_DIR}\"). Check your path parameter."
my_usage
exit 1
fi
### check if the tsv files are available to call download scripts
tsv_files="PSV_GAMES.tsv PSV_DLCS.tsv PSV_UPDATES.tsv"
for tsv_file in $tsv_files
do
if [ ! -f "${NPS_DIR}/${tsv_file}" ]
then
echo "*.tsv file \"${tsv_file}\" in path \"${NPS_DIR}\" missing."
exit 1
fi
done
### Download the chosen game
nps_game.sh "${NPS_DIR}/PSV_GAMES.tsv" "${TITLE_ID}"
if [ ${?} -ne 0 ]
then
echo ""
echo "Game cannot be downloaded. Skipping further steps."
exit 1
fi
### Get name of the zip file from generated txt created via nps_game.sh
GAME_NAME="$(cat "${TITLE_ID}.txt")"
GAME_NAME="$(region_rename "${GAME_NAME}")"
ZIP_FILENAME="${GAME_NAME}.${ext}"
### Download available updates. With parameter -a all updates
if [ "${UPDATE_ALL}" -eq 1 ]
then
DESTDIR="${GAME_NAME}" nps_update.sh -a "${TITLE_ID}"
else
DESTDIR="${GAME_NAME}" nps_update.sh "${TITLE_ID}"
fi
### Download available DLC
DESTDIR="${GAME_NAME}" nps_dlc.sh "${NPS_DIR}/PSV_DLCS.tsv" "${TITLE_ID}"
### Creating the torrent files
if [ ${CREATE_TORRENT} -eq 1 ]
then
rm -f "${ZIP_FILENAME}.torrent"
echo "Creating torrent file for \"${GAME_NAME}.${ext}\""
my_mktorrent "${ZIP_FILENAME}"
if [ -d "${GAME_NAME}_update" ]
then
test -e "${GAME_NAME}_update.torrent" && rm -f "${GAME_NAME}_update.torrent"
echo "Creating torrent file for directory \"${GAME_NAME}_update\""
my_mktorrent "${GAME_NAME}_update"
fi
if [ -d "${GAME_NAME}_dlc" ]
then
test -e "${GAME_NAME}_dlc.torrent" && rm -f "${GAME_NAME}_dlc.torrent"
echo "Creating torrent file for directory \"${GAME_NAME}_dlc\""
my_mktorrent "${GAME_NAME}_dlc"
fi
fi
### remove temporary game name file
rm "${TITLE_ID}.txt"
### Run post scripts
if [ -x ./nps_bundle_post.sh ]
then
./nps_bundle_post.sh "${GAME_NAME}"
fi