-
Notifications
You must be signed in to change notification settings - Fork 8
/
package_build
executable file
·186 lines (168 loc) · 5.55 KB
/
package_build
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
#!/usr/bin/env bash
packaging_path=`pwd`
git_repo='https://github.com/persepolisdm/persepolis.git'
venv_dir='venv'
error_color='\033[1;31m✗'
warn_color='\033[1;33m▶︎'
success_color='\033[1;32m✔︎'
reset_color='\033[0m'
error_msg() {
echo -e "$error_color $1$reset_color"; exit 1;
}
warn_msg() {
echo -e "$warn_color $1$reset_color";
}
success_msg() {
echo -e "$success_color $1$reset_color";
}
clean_build_files () {
warn_msg 'Removing {persepolis, dist, build} directories'
if [[ -d 'persepolis' ]] ; then
warn_msg "persepolis directory (git cloned dir) exist, Are you sure to remove it? [y/Y]"
read ans
if [[ ($ans == 'y') || ($ans == 'Y') ]]; then
rm -rf persepolis
fi
fi
rm -rf dist/dmg dist build
if [ "$1" = "include_spec_file" ]; then
warn_msg 'remove .spec file'
rm 'Persepolis Download Manager.spec'
fi
}
download_ffmpeg() {
warn_msg "downloading ffmpeg"
wget --trust-server-names https://evermeet.cx/ffmpeg/getrelease/ffmpeg/zip -O ffmpeg.zip && unzip -o ffmpeg.zip && rm ffmpeg.zip
if [[ $? -ne 0 ]]; then
error_msg 'downloading ffmpeg is failed, check connection'
else
success_msg 'ffmpeg downloaded'
fi
}
update_dependencies() {
warn_msg "Do you want update all dependencies? [y/Y]"
read ans
if [[ ($ans == 'y') || ($ans == 'Y') ]]; then
pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
if [[ $? -ne 0 ]]; then
error_msg 'updating dependencies failed'
else
success_msg 'all dependencies was successfully updated'
fi
fi
}
check_installed_brew(){
which -s brew
if [[ $? != 0 ]] ; then
warn_msg "Do you want install homebrew for packaging? [y/Y]"
read ans
if [[ ($ans == 'y') || ($ans == 'Y') ]]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if [[ $? -ne 0 ]]; then
error_msg 'installing brew failed'
else
success_msg 'brew was successfully installed'
fi
fi
else
success_msg 'brew is installed on your system'
fi
}
check_installed_wget(){
if brew ls --versions wget > /dev/null; then
success_msg 'wget is installed on your system'
else
warn_msg "Do you want install wget with homebrew? [y/Y]"
read ans
if [[ ($ans == 'y') || ($ans == 'Y') ]]; then
brew install wget
if [[ $? -ne 0 ]]; then
error_msg 'installing wget failed'
else
success_msg 'wget was successfully installed'
fi
fi
fi
}
check_installed_createdmg() {
if brew ls --versions create-dmg > /dev/null; then
success_msg 'create-dmg is installed on your system'
else
warn_msg "Do you want install create-dmg with homebrew? [y/Y]"
read ans
if [[ ($ans == 'y') || ($ans == 'Y') ]]; then
brew install create-dmg
if [[ $? -ne 0 ]]; then
error_msg 'installing create-dmg failed'
else
success_msg 'create-dmg was successfully installed'
fi
fi
fi
}
build_dmg_installer(){
mkdir -p dist/dmg
mv 'Persepolis Download Manager.app' dist/dmg
test -f "dist/Persepolis Download Manager.dmg" && rm "dist/Persepolis Download Manager.dmg"
create-dmg \
--volname "Persepolis Download Manager" \
--volicon "icon.icns" \
--window-pos 200 120 \
--window-size 600 300 \
--icon-size 100 \
--icon "Persepolis Download Manager.app" 120 120 \
--hide-extension "Persepolis Download Manager.app" \
--app-drop-link 425 120 \
"Persepolis Download Manager.dmg" \
"dist/dmg/"
}
while getopts ":a:v:h" o; do
case "$o" in
a)
grep -q '\.git$' <<< ${OPTARG} && git_repo=${OPTARG}
;;
v)
venv_dir=${OPTARG}
;;
h)
echo "Usage: $0 [ -a $git_repo -v virtualenv_dir_name ]" 1>&2; exit 1;
;;
esac
done
shift $((OPTIND-1))
cd "$packaging_path"
if [[ ! (-d "$venv_dir") ]] ; then
which virtualenv
if [[ $? -ne 0 ]]; then
error_msg 'You must install virtualenv!'
fi
virtualenv -p python3 "$venv_dir"
if [[ $? -ne 0 ]]; then
rm -rf "$venv_dir"
echo $venv_dir
error_msg 'Virtualenv creation failed!'
fi
success_msg 'Virtualenv directory created'
fi
source "./$venv_dir/usr/local/bin/activate"
pip install -r ./requirements.txt
if [[ $? -ne 0 ]]; then
error_msg 'Resolving python dependency failed'
else
success_msg 'Python dependecy installed'
fi
update_dependencies
check_installed_brew
check_installed_wget
clean_build_files
[[ ! (-d './persepolis') ]] && git clone "$git_repo" persepolis && success_msg "$git_repo cloned"
find persepolis/persepolis -type f -exec perl -i -pe 's/persepolis.scripts/scripts/g' '{}' \;
find persepolis/persepolis -type f -exec perl -i -pe 's/persepolis.gui/gui/g' '{}' \;
pyinstaller app.spec
download_ffmpeg
[ -d './dist' ] && cp ffmpeg 'dist/Persepolis Download Manager.app/Contents/MacOS/' && success_msg 'ffmpeg is added to package'
[ -d './Persepolis Download Manager.app' ] && [ -d './dist' ] && rm -rf 'Persepolis Download Manager.app'
[ -d './dist' ] && mv 'dist/Persepolis Download Manager.app' . && success_msg 'final package moving to root directory'
check_installed_createdmg
build_dmg_installer
clean_build_files