forked from tossp/redpill-tool-chain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.sh
executable file
·137 lines (115 loc) · 4.53 KB
/
helper.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
#!/usr/bin/env bash
set -u
if [ ${TARGET_REVISION} -lt 42661 ];then
exit 0
fi
cat ./redpill-load/build-loader.sh | head -n `expr -1 + $(sed -n '/Printing config variables/=' ./redpill-load/build-loader.sh)` > ./redpill-load/_helper.sh
. ./redpill-load/_helper.sh "${TARGET_NAME}" "${TARGET_VERSION}-${TARGET_REVISION}"
rm ./_helper.sh
# Repacks tar-like file
#
# Args: $1 directory to unpack (must exist) | $2 file path | $3 should hard fail on error? [default=1]
brp_repack_tar()
{
pr_process "Repacking %s file form %s" "${2}" "${1}"
local output;
output=$("${TAR_PATH}" -czf "${2}" -C "${1}" . 2>&1)
if [ $? -ne 0 ]; then
pr_process_err
if [[ "${3:-1}" -ne 1 ]]; then
pr_err "Failed to unpack tar\n\n%s" "${output}"
return 1
else
pr_crit "Failed to unpack tar\n\n%s" "${output}"
fi
fi
pr_process_ok
}
readonly extract_bin='/usr/local/bin/syno_extract_system_patch'
make_extract(){
archive="$1"
if [ ! -f "${extract_bin}" ]; then
pr_dbg "%s not found - preparing" "${extract_bin}"
if [ ! -f "${EXTRACT_PAT_FILE}" ]; then
rpt_download_remote "${EXTRACT_PAT_URL}" "${EXTRACT_PAT_FILE}"
else
pr_dbg "Found existing PAT at %s - skipping download" "${EXTRACT_PAT_FILE}"
fi
pr_dbg "Found syno_extract_system_patch File not found - preparing" "${extract_bin}"
brp_mkdir /tmp/synoesp && brp_unpack_tar "${EXTRACT_PAT_FILE}" "/tmp/synoesp"
brp_mkdir /tmp/extract && brp_unpack_zrd "/tmp/synoesp/rd.gz" "/tmp/extract"
cp /tmp/extract/usr/lib/{libcurl.so.4,libmbedcrypto.so.5,libmbedtls.so.13,libmbedx509.so.1,libmsgpackc.so.2,libsodium.so,libsynocodesign-ng-virtual-junior-wins.so.7} /usr/local/lib
cp /tmp/extract/usr/syno/bin/scemd ${extract_bin}
rm -rf /tmp/synoesp /tmp/extract
else
pr_dbg "Found syno_extract_system_patch File at %s - skipping nake" "${extract_bin}"
fi
pr_process "Use syno_extract_system_patch extract PAT"
LD_LIBRARY_PATH=/usr/local/lib ${extract_bin} "${BRP_PAT_FILE}" /tmp/pat && pr_process_ok || pr_process_err
brp_repack_tar "/tmp/pat/" /tmp/repack.tar.gz
pr_process "New checksum of PAT %s - Patch the PAT checksum" ${BRP_PAT_FILE}
mv ${BRP_PAT_FILE} ${BRP_PAT_FILE}.org && mv /tmp/repack.tar.gz ${BRP_PAT_FILE} && rm -rf "/tmp/pat"
sum=`sha256sum ${BRP_PAT_FILE} | awk '{print $1}'`
old_sum="$(brp_json_get_field "${BRP_REL_CONFIG_JSON}" "os.sha256")"
sed -i "s/${old_sum}/${sum}/" "${BRP_REL_CONFIG_JSON}"
rm -rf /tmp/pat
pr_process_ok
}
check_pat() {
archive="$1"
archiveheader="$(od -bc ${archive} | head -1 | awk '{print $3}')"
return_value=0
case ${archiveheader} in
105)
pr_dbg "${archive}, is a Tar file"
;;
255)
pr_info "File ${archive}, Decryption required"
return_value=1
;;
213)
pr_dbg "File ${archive}, is a compressed tar"
;;
*)
pr_process_err
pr_err "Could not determine if file ${archive} is encrypted or not, maybe corrupted"
ls -ltr ${archive}
pr_crit "${archiveheader}"
return_value=99
;;
esac
return $return_value
}
##########################################################
# fix redo
readonly BRP_PAT_FILE="${BRP_CACHE_DIR}/${BRP_REL_OS_ID}.pat"
readonly EXTRACT_PAT_FILE="${BRP_CACHE_DIR}/extract.tar.gz"
readonly EXTRACT_PAT_URL='https://global.download.synology.com/download/DSM/release/7.0.1/42218/DSM_DS3615xs_42218.pat'
if [ -f "${BRP_PAT_FILE}.org" ] && [ -f "${BRP_PAT_FILE}" ]; then
pr_info "Found patched PAT file - Patch the PAT checksum"
file_sum="$(brp_json_get_field "${BRP_REL_CONFIG_JSON}" "os.sha256")"
new_sum=`sha256sum "${BRP_PAT_FILE}" | awk '{print $1}'`
org_sum=`sha256sum "${BRP_PAT_FILE}.org" | awk '{print $1}'`
if [ "$new_sum" != "$file_sum" ] && [ "$org_sum" == "$file_sum" ]; then
sed -i "s/${org_sum}/${new_sum}/" "${BRP_REL_CONFIG_JSON}"
fi
fi
if [ ! -d "${BRP_UPAT_DIR}" ]; then
pr_dbg "Unpacked PAT %s not found - preparing" "${BRP_UPAT_DIR}"
brp_mkdir "${BRP_UPAT_DIR}"
if [ ! -f "${BRP_PAT_FILE}" ]; then
rpt_download_remote "$(brp_json_get_field "${BRP_REL_CONFIG_JSON}" "os.pat_url")" "${BRP_PAT_FILE}"
else
pr_dbg "Found existing PAT at %s - skipping download" "${BRP_PAT_FILE}"
fi
brp_verify_file_sha256 "${BRP_PAT_FILE}" "$(brp_json_get_field "${BRP_REL_CONFIG_JSON}" "os.sha256")"
check_pat "${BRP_PAT_FILE}"
exec_status=$?
pr_info "Test encryption pat results %s" "${exec_status}"
if [ "$exec_status" -eq 1 ]; then
pr_empty_nl
make_extract "${BRP_PAT_FILE}"
fi
else
pr_info "Found unpacked PAT at \"%s\" - skipping unpacking" "${BRP_UPAT_DIR}"
fi