-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.sh
executable file
·190 lines (158 loc) · 5.49 KB
/
publish.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
#!/bin/sh
COLOR_RED='\033[0;31m' # Red
COLOR_GREEN='\033[0;32m' # Green
COLOR_YELLOW='\033[0;33m' # Yellow
COLOR_BLUE='\033[0;34m' # Blue
COLOR_PURPLE='\033[0;35m' # Purple
COLOR_OFF='\033[0m' # Reset
print() {
printf "%b" "$*"
}
echo() {
print "$*\n"
}
info() {
echo "$COLOR_PURPLE==>$COLOR_OFF $COLOR_GREEN$@$COLOR_OFF"
}
success() {
print "${COLOR_GREEN}[✔] $*\n${COLOR_OFF}"
}
warn() {
print "${COLOR_YELLOW}🔥 $*\n${COLOR_OFF}" >&2
}
error() {
print "${COLOR_RED}[✘] $*\n${COLOR_OFF}" >&2
}
die() {
print "${COLOR_RED}[✘] $*\n${COLOR_OFF}" >&2
exit 1
}
# check if file exists
# $1 FILEPATH
file_exists() {
[ -n "$1" ] && [ -e "$1" ]
}
# check if command exists in filesystem
# $1 command name or path
command_exists_in_filesystem() {
case $1 in
*/*) executable "$1" ;;
*) command -v "$1" > /dev/null
esac
}
executable() {
file_exists "$1" && [ -x "$1" ]
}
die_if_file_is_not_exist() {
file_exists "$1" || die "$1 is not exists."
}
die_if_not_executable() {
executable "$1" || die "$1 is not executable."
}
step() {
STEP_NUM=$(expr ${STEP_NUM-0} + 1)
STEP_MESSAGE="$@"
echo
echo "${COLOR_PURPLE}=>> STEP ${STEP_NUM} : ${STEP_MESSAGE} ${COLOR_OFF}"
}
run() {
info "$*"
eval "$*"
}
sed_in_place() {
if command -v gsed > /dev/null ; then
unset SED_IN_PLACE_ACTION
SED_IN_PLACE_ACTION="$1"
shift
# contains ' but not contains \'
if printf "$SED_IN_PLACE_ACTION" | hexdump -v -e '1/1 "%02X" " "' | grep -q 27 && ! printf "$SED_IN_PLACE_ACTION" | hexdump -v -e '1/1 "%02X" ""' | grep -q '5C 27' ; then
run gsed -i "\"$SED_IN_PLACE_ACTION\"" $@
else
run gsed -i "'$SED_IN_PLACE_ACTION'" $@
fi
elif command -v sed > /dev/null ; then
if sed -i 's/a/b/g' $(mktemp) 2> /dev/null ; then
unset SED_IN_PLACE_ACTION
SED_IN_PLACE_ACTION="$1"
shift
if printf "$SED_IN_PLACE_ACTION" | hexdump -v -e '1/1 "%02X" " "' | grep -q 27 && ! printf "$SED_IN_PLACE_ACTION" | hexdump -v -e '1/1 "%02X" ""' | grep -q '5C 27' ; then
run sed -i "\"$SED_IN_PLACE_ACTION\"" $@
else
run sed -i "'$SED_IN_PLACE_ACTION'" $@
fi
else
unset SED_IN_PLACE_ACTION
SED_IN_PLACE_ACTION="$1"
shift
if printf "$SED_IN_PLACE_ACTION" | hexdump -v -e '1/1 "%02X" " "' | grep -q 27 && ! printf "$SED_IN_PLACE_ACTION" | hexdump -v -e '1/1 "%02X" ""' | grep -q '5C 27' ; then
run sed -i '""' "\"$SED_IN_PLACE_ACTION\"" $@
else
run sed -i '""' "'$SED_IN_PLACE_ACTION'" $@
fi
fi
else
die "please install sed utility."
fi
}
#examples:
# printf ss | sha256sum
# cat FILE | sha256sum
# sha256sum < FILE
sha256sum() {
if [ $# -eq 0 ] ; then
if echo | command sha256sum > /dev/null 2>&1 ; then
command sha256sum | cut -d ' ' -f1
elif command -v openssl > /dev/null ; then
openssl sha256 | rev | cut -d ' ' -f1 | rev
else
return 1
fi
else
die_if_file_is_not_exist "$1"
if command -v openssl > /dev/null ; then
openssl sha256 "$1" | cut -d ' ' -f2
elif echo | command sha256sum > /dev/null 2>&1 ; then
command sha256sum "$1" | cut -d ' ' -f1
else
die "please install openssl or GNU CoreUtils."
fi
fi
}
main() {
set -e
command -v makepkg > /dev/null || die "please install makepkg."
unset RELEASE_VERSION
unset RELEASE_FILE_NAME
unset RELEASE_FILE_SHA256SUM
RELEASE_VERSION=$(bin/androidx --version)
RELEASE_FILE_NAME="androidx-$RELEASE_VERSION.tar.gz"
run tar zvcf "$RELEASE_FILE_NAME" bin/androidx zsh-completion/_androidx
RELEASE_FILE_SHA256SUM=$(sha256sum "$RELEASE_FILE_NAME")
success "sha256sum($RELEASE_FILE_NAME)=$RELEASE_FILE_SHA256SUM"
sed_in_place "s|sha256sums=(.*)|sha256sums=(\'$RELEASE_FILE_SHA256SUM\')|" PKGBUILD
sed_in_place "s|pkgver=.*|pkgver=\'$RELEASE_VERSION\'|" PKGBUILD
sed_in_place "s|VERSION='[0-9].[0-9].[0-9]'|VERSION='$RELEASE_VERSION'|" install.sh
sed_in_place "s|v[0-9].[0-9].[0-9]|v$RELEASE_VERSION|" README.md
sed_in_place "s|androidx-[0-9].[0-9].[0-9]|androidx-$RELEASE_VERSION|g" README.md
run makepkg
run git add PKGBUILD README.md install.sh
run git commit -m "'publish new version $RELEASE_VERSION'"
run git push origin master
run gh release create v"$RELEASE_VERSION" "androidx-$RELEASE_VERSION.tar.gz" "androidx-$RELEASE_VERSION-1-any.pkg.tar.gz" --notes "'release $RELEASE_VERSION'"
run git clone [email protected]:leleliu008/homebrew-fpliu.git
run cd homebrew-fpliu
sed_in_place '/url /d' Formula/androidx.rb
sed_in_place '/sha256 /d' Formula/androidx.rb
sed_in_place "/homepage/a \ sha256 \"$RELEASE_FILE_SHA256SUM\"" Formula/androidx.rb
sed_in_place "/homepage/a \ url \"https://github.com/leleliu008/androidx/releases/download/v$RELEASE_VERSION/androidx-$RELEASE_VERSION.tar.gz\"" Formula/androidx.rb
run git add Formula/androidx.rb
run git commit -m "'publish new version androidx-$RELEASE_VERSION'"
run git push origin master
run cd ..
run rm -rf homebrew-fpliu
run rm "$RELEASE_FILE_NAME"
run rm "androidx-$RELEASE_VERSION-1-any.pkg.tar.gz"
run rm -rf pkg
run rm -rf src
}
main $@