forked from nathanchance/env
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsign
More file actions
executable file
·101 lines (78 loc) · 2.41 KB
/
sign
File metadata and controls
executable file
·101 lines (78 loc) · 2.41 KB
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
#!/usr/bin/env bash
#
# Zip signing script
#
# Copyright (C) 2017 Nathan Chancellor
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
###############
# #
# FUNCTIONS #
# #
###############
# SOURCE OUR UNIVERSAL FUNCTIONS SCRIPT (DON'T MAC CHECK)
source common -m
################
# #
# PARAMETERS #
# #
################
while [[ $# -ge 1 ]]; do
case "${1}" in
# FILE TO SIGN
"-f"|"--file")
shift && enforce_value "$@"
FILE=${1} ;;
# KEY TO USE
"-k"|"--key")
shift && enforce_value "$@"
KEY=${1} ;;
*)
report_error "Invalid parameter!" ;;
esac
shift
done
# Defaults and sanity check
[[ -z ${FILE} ]] && report_error "You didn't specify a file!"
[[ -z ${KEY} ]] && KEY=testkey
# Error out if the file isn't a zip file
[[ $(echo ${FILE} | grep -v zip) ]] && report_error "This can only sign zip files!"
##############
# #
# SIGN ZIP #
# #
##############
# Show some text
header "Signing ${FILE}"
# Shift to the folder containing the zip
cd $(dirname ${FILE})
# Get the zip name
ZIP_NAME=$(basename ${FILE} .zip)
# Sign the zip
java -jar ${BIN_FOLDER}/signapk.jar \
${BIN_FOLDER}/${KEY}.x509.pem \
${BIN_FOLDER}/${KEY}.pk8 \
${ZIP_NAME}.zip \
${ZIP_NAME}-firstsign.zip
${BIN_FOLDER}/zipadjust ${ZIP_NAME}-firstsign.zip \
${ZIP_NAME}-adjusted.zip &>/dev/null
java -jar ${BIN_FOLDER}/minsignapk.jar \
${BIN_FOLDER}/${KEY}.x509.pem \
${BIN_FOLDER}/${KEY}.pk8 \
${ZIP_NAME}-adjusted.zip \
${ZIP_NAME}-signed.zip
# Remove intermediate zip files
rm ${ZIP_NAME}-firstsign.zip ${ZIP_NAME}-adjusted.zip
# Echo zip location
echo "Signed zip: $(pwd)/${ZIP_NAME}-signed.zip\n"