This repository has been archived by the owner on Mar 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
pype
executable file
·858 lines (792 loc) · 25.9 KB
/
pype
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
#!/usr/bin/env bash
# ____________ ____ ____ ____________ ____________
# / \ \/\ \ /\ \/\ \/\ \
# \ \ --- \ \ \___\_\ \ \ --- \ \ ------\
# \ \ _____/ \____ ____\ \ _____/ \ \___\
# \ \ \__/ \____/ \ \__/\ \ \__/ \ \ -------\
# \ \____\ \ \____\ \ \____\ \ \___________\
# \/____/ \/____/ \/____/ \/___________/
#
# ... █░░ --=[ CLuB ]]=-- ░░█ ...
# Print Pype ascii art :)
art () {
cat <<-EOF
____________
/\\ \\
\\ \\ --- \\
\\ \\ _____/ ______
\\ \\ \\___/ /\\ \\
\\ \\____\\ \\ \\_____\\
\\/____/ \\/_____/ PYPE Club .
EOF
}
# Full path of the current script
THIS=`readlink -f "${BASH_SOURCE[0]}" 2>/dev/null||echo $0`
# The directory where current script resides
DIR=`dirname "${THIS}"`
pushd "$DIR" > /dev/null
# Set python interpreter name
PYTHON="python3"
# Set path to environment if not set
if [[ "$OSTYPE" =~ ^darwin.* ]]; then
export PYPE_ENV=${PYPE_ENV:="/usr/local/pype/pype_env2"}
else
export PYPE_ENV=${PYPE_ENV:="/opt/pype/pype_env2"}
fi
# Set debug level if not set
export PYPE_DEBUG=${PYPE_DEBUG:=0}
# Process passed arguments
# Initialize vars
f_offline=0
f_install=0
f_deploy=0
f_download=0
f_help=0
f_validate=0
f_force=0
f_mongodb=0
f_update=0
f_clean=0
f_macIcons=0
f_localize=0
venv_activated=0
# Process arguments
# .
args=$@
while :; do
case $1 in
install)
f_install=1
;;
--force)
f_force=1
;;
--offline)
f_offline=1
;;
help)
f_help=1
;;
--help)
f_help=1
;;
download)
f_download=1
;;
deploy)
f_deploy=1
;;
validate)
f_validate=1
;;
mongodb)
f_mongodb=1
;;
update-requirements)
f_update=1
;;
clean)
f_clean=1
;;
mac-icons)
f_macIcons=1
;;
localize-bin)
f_localize=1
;;
--)
shift
break
;;
*)
break
esac
shift
done
# -----------------------------------------------------------------------------
# Initialize important environment variables
# Set PYPE_SETUP_PATH to path to this script
if [[ -z $PYPE_SETUP_PATH ]]; then
export PYPE_SETUP_PATH=$(cd "$DIR"; pwd)
fi
# Add PYPE_SETUP_PATH to PYTHONPATH if missing
export PYTHONPATH=${PYTHONPATH:="$PYPE_SETUP_PATH/pypeapp"}
if [[ ":$PYTHONPATH:" != *":$PYPE_SETUP_PATH/pypeapp:"* ]]; then
export PYTHONPATH="$PYPE_SETUP_PATH/pypeapp:$PYTHONPATH"
fi
if [[ ":$PYTHONPATH:" != *":$PYPE_SETUP_PATH:"* ]]; then
export PYTHONPATH="$PYPE_SETUP_PATH:$PYTHONPATH"
fi
# add PYPE_SETUP_PATH to PATH
export PATH=${PATH:="$PYPE_SETUP_PATH"}
if [[ ":$PATH:" != *":$PYPE_SETUP_PATH:"* ]]; then
export PATH="$PYPE_SETUP_PATH:$PATH"
fi
export PATH="$PYPE_SETUP_PATH/vendor/bin/ffmpeg_exec/linux/bin:$PATH"
# Load colors definitions for easy output coloring
if [[ -z $PYPE_LOG_NO_COLORS ]]; then
source "$PYPE_SETUP_PATH/pypeapp/colors.sh"
fi
###############################################################################
# Test if Xcode Command Line tools are installed in MacOS
###############################################################################
have_command_line_tools() {
[[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]]
}
###############################################################################
# Get command any key from user
###############################################################################
getc() {
local save_state
save_state=$(/bin/stty -g)
/bin/stty raw -echo
IFS= read -r -n 1 -d '' "$@"
/bin/stty "$save_state"
}
###############################################################################
# Test if we have access via sudo
# Used in MacOS
###############################################################################
have_sudo_access() {
if [[ -z "${HAVE_SUDO_ACCESS-}" ]]; then
/usr/bin/sudo -l mkdir &>/dev/null
HAVE_SUDO_ACCESS="$?"
fi
if [[ "$HAVE_SUDO_ACCESS" -ne 0 ]]; then
echo -e "${BIRed}!!!${RST} Need sudo access on MacOS"
return 1
fi
return "$HAVE_SUDO_ACCESS"
}
###############################################################################
# Execute command and report failure
###############################################################################
execute() {
if ! "$@"; then
echo -e "${BIRed}!!!${RST} Failed execution of ${BIWhite}[ $@ ]${RST}"
fi
}
###############################################################################
# Execute command using sudo
# This is used on MacOS to handle Xcode command line tools installation
###############################################################################
execute_sudo() {
local -a args=("$@")
if [[ -n "${SUDO_ASKPASS-}" ]]; then
args=("-A" "${args[@]}")
fi
if have_sudo_access; then
echo -e "${BIGreen}>->${RST} sudo: [${BIWhite} ${args[@]} ${RST}]"
execute "/usr/bin/sudo" "${args[@]}"
else
echo -e "${BIGreen}>->${RST} [${BIWhite} ${args[@]} ${RST}]"
execute "${args[@]}"
fi
}
###############################################################################
# Display spinner for running job. Job must be running in a background.
# Usage:
# run_job 2> /dev/null &
# spinner
# Globals:
# PID of background job
# Arguments:
# None
# Returns:
# None
###############################################################################
spinner () {
local pid=$!
local delay=0.75
local spinstr='|/-\'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
}
###############################################################################
# Activate virtual environment
# Globals:
# colors
# venv_activated
# Arguments:
# environment
# Returns:
# 1 if failed
###############################################################################
activate_venv () {
echo -e "${BICyan}-->${RST} Activating environment [${BIWhite} $1 ${RST}]"
source "$1/bin/activate"
if [ $? -ne 0 ] ; then
echo -e "${BIRed}!!!${RST} Failed to activate."
return 1
fi
venv_activated=1
}
##############################################################################
# Deactivate virtual environment
# Globals:
# colors
# venv_activated
# Arguments:
# None
# Returns:
# None
###############################################################################
deactivate_venv () {
if [ $venv_activated -eq 1 ] ; then
echo -e "${BICyan}<--${RST} Deactivating environment [${BIWhite} $1 ${RST}]"
deactivate
venv_activated=0
fi
}
##############################################################################
# Update requirements with stuff based on what is installed in current
# active python (virtual) environment.
# Globals:
# colors
# Arguments:
# None
# Returns:
# None
###############################################################################
update_requirements () {
echo -e "${BICyan} -${RST} Updating requirements ..."
pip3 freeze > pypeapp/requirements.txt
}
##############################################################################
# Install virtual environment
# Globals:
# colors
# f_help
# f_force
# PYPE_ENV
# PYTHON
# Arguments:
# None
# Returns:
# 1 if failed
###############################################################################
install_environment () {
# if ran with --help, pass control to python to print help message and
# terminate.
if [ "$f_help" == 1 ] ; then
local install_command="$PYTHON -m pypeapp install --help"
${install_command}
return 1
fi
echo -e "${IGreen}>>>${RST} Installing environment to [${BIWhite} $PYPE_ENV ${RST}] ..."
if [ "$f_force" == 1 ] ; then
local install_command="$PYTHON -m pypeapp install --force"
${install_command}
else
local install_command="$PYTHON -m pypeapp install"
${install_command}
fi
if [ $? -ne 0 ] ; then
echo -e "${BIRed}!!!${RST} Installation failed (${BIYellow}$?${RST})"
return 1
fi
}
##############################################################################
# This checks current environment against pype's requirement.txt
# Globals:
# colors
# f_offline
# PYPE_SETUP_PATH
# Arguments:
# None
# Returns:
# None
###############################################################################
check_environment () {
echo -e "${IGreen}>>>${RST} Validating environment dependencies ... \c"
$PYTHON "$PYPE_SETUP_PATH/pypeapp/requirements.py"
if [ $? -ne 0 ] ; then
echo -e "${BIYellow}FAILED${RST}"
echo -e "${BIYellow}***${RST} Environment dependencies inconsistent, fixing ..."
test_offline
if [ "$f_offline" -ne 1 ]; then
pip3 install -r "$PYPE_SETUP_PATH/pypeapp/requirements.txt"
else
pip3 install -r "$PYPE_SETUP_PATH/pypeapp/requirements.txt" --no-index --find-links "$PYPE_SETUP_PATH/vendor/packages"
fi
if [ $? -ne 0 ] ; then
echo -e "${BIRed}!!!${RST} Installaton ${BIRed}FAILED${RST}"
return 1
fi
clean_pyc $PYPE_ENV
clean_pyc
if [[ $OSTYPE =~ ^darwin.* ]]; then
f_macIcons=1
fi
else
echo -e "${BIGreen}OK${RST}"
fi
}
##############################################################################
# Upgrade pip
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
upgrade_pip () {
if [ "$f_offline" -ne 1 ] ; then
echo -e "${BIGreen}>>>${RST} Updating pip ..."
pip3 install --upgrade pip 2> /dev/null
fi
}
##############################################################################
# This will install all requirements necessary from requirements.txt
# Globals:
# colors
# f_offline
# PYPE_SETUP_PATH
# Arguments:
# None
# Returns:
# 1 if failed
###############################################################################
bootstrap_pype () {
if [ "$f_offline" -ne 1 ] ; then
# ensure latest pip version
upgrade_pip
echo -e "${BIGreen}>>>${RST} Bootstrapping Pype ..."
# install essential dependecies
echo -e "${BICyan} -${RST} Installing dependecies ..."
pip3 install -r "$PYPE_SETUP_PATH/pypeapp/requirements.txt"
if [ $? -ne 0 ] ; then
echo -e "${BIRed}!!!${RST} Installaton ${BIRed}FAILED${RST}"
return 1
fi
else
# in offline mode, install all from vendor
echo -e "${BIGreen}>>>${RST} Offline installation ..."
pip3 install -r "$PYPE_SETUP_PATH/pypeapp/requirements.txt" --no-index --find-links vendor/packages
if [ $? -ne 0 ] ; then
echo -e "${BIRed}!!! ${RST} Installation ${BIRed}FAILED${RST}"
return 1
fi
fi
}
##############################################################################
# This will pass control to python to deploy repositories and stuff
# Requires git
# Globals:
# colors
# f_force
# f_help
# Arguments:
# None
# Returns:
# 1 for exit
###############################################################################
deploy_pype () {
if [ $f_help == 1 ] ; then
$PYTHON -m pypeapp deploy --help
return 1
fi
if [ $f_force == 1 ] ; then
$PYTHON -m pypeapp deploy --force
else
$PYTHON -m pypeapp deploy
fi
if [ $? -ne 0 ] ; then
echo -e "${BIRed}!!!${RST} Deployment ${BIRed}FAILED${RST}"
return 1
fi
}
##############################################################################
# This will validate pype deployment.
# It will pass control to python to validate repositories deployment.
# Requires git
# Globals:
# colors
# f_help
# Arguments:
# None
# Returns:
# 1 if failed
###############################################################################
validate_pype () {
if [ "$f_help" == 1 ] ; then
$PYTHON -m pypeapp validate --help
return 1
fi
$PYTHON -m pypeapp validate
if [ $? -ne 0 ] ; then
echo -e "${BIRed}!!! WARNING:${RST} Deployment is invalid."
echo -e "${BIYellow} *${RST} Contact your system administrator to resolve this issue."
echo -e "${BIYellow} *${RST} You can try to fix deployment with ${BIWhite}pype deploy --force${RST}"
return 1
fi
}
##############################################################################
# Function to detect mongod in path
# Requires mongod
# Globals:
# colors
# Arguments:
# None
# Returns:
# None
###############################################################################
detect_mongo () {
if [ "$f_mongodb" == 1 ] ; then
echo -e "${BIGreen}>>>${RST} looking for ${BIWhite}[ mongod ]${RST} ... \c"
command -v mongod >/dev/null 2>&1 || { echo -e "${BIRed}FAILED${RST}"; echo -e "${BIRed}!!!${RST} Mongod wasn't found in PATH"; return 1; }
echo -e "${BIGreen}OK${RST}"
fi
}
##############################################################################
# Detect required version of python
# Requires mongod
# Globals:
# colors
# PYTHON
# Arguments:
# None
# Returns:
# None
###############################################################################
detect_python () {
# override Python interpreter if needed
if [[ -z $PYPE_PYTHON_EXE ]]; then
echo -e "${BIGreen}>>>${RST} looking for ${BIWhite}[ python ]${RST} ... \c"
command -v $PYTHON >/dev/null 2>&1 || { echo -e "${BIRed}FAILED${RST}"; return 1; }
# Parse version string
local version_command="import sys;print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1]))"
local python_version="$($PYTHON <<< ${version_command})"
export PYTHON_VERSION=$python_version
oIFS="$IFS"
IFS=.
set -- $python_version
IFS="$oIFS"
if [ "$1" -ge "3" ] && [ "$2" -ge "6" ] ; then
echo -e "${BIGreen}$1.$2${RST}"
else
# Python is old, but maybe we have newer just not symlinked to `python`
PYTHON="python3.6"
command -v $PYTHON >/dev/null 2>&1 || { echo -e "${BIRed}FAILED${RST} ${BIYellow} Version [${RST}${BICyan}$1.$2${RST}]${BIYellow} is old and unsupported${RST}"; return 1; }
# If so, change python interpreter name
local python_version="$($PYTHON <<< ${version_command})"
oIFS="$IFS"
IFS=.
set -- $python_version
IFS="$oIFS"
echo -e "${BIGreen}$1.$2${RST}"
fi
else
echo -e "${BIYellow}>>>${RST} Forced using python at [ ${BIWhite}[ $PYPE_PYTHON_EXE ]${RST} ... \c"
local version_command="import sys;print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1]))"
local python_version="$($PYPE_PYTHON_EXE <<< ${version_command})"
oIFS="$IFS"
IFS=.
set -- $python_version
IFS="$oIFS"
if [ "$1" -ge "3" ] && [ "$2" -ge "6" ] ; then
echo -e "${BIGreen}$1.$2${RST}"
PYTHON=$PYPE_PYTHON_EXE
else
command -v $PYPE_PYTHON_EXE >/dev/null 2>&1 || { echo -e "${BIRed}FAILED${RST} ${BIYellow} Version [${RST}${BICyan}$1.$2${RST}]${BIYellow} is old and unsupported${RST}"; return 1; }
fi
fi
}
##############################################################################
# Function to detect git in path
# Requires git
# Globals:
# colors
# Arguments:
# None
# Returns:
# None
###############################################################################
detect_git () {
echo -e "${BIYellow}---${RST} looking for ${BIWhite}[ git ]${RST} ... \c"
command -v git >/dev/null 2>&1 || { echo -e "${BIRed}FAILED${RST}"; return 1; }
echo -e "${BIGreen}OK${RST}"
}
##############################################################################
# Using ping testing if we have internet connection
# Globals:
# colors
# f_offline
# Arguments:
# None
# Returns:
# 1 if we are offline
###############################################################################
test_offline () {
echo -e "${BIGreen}>>>${RST} Testing if we are online ... \c"
local wait="-w1"
if [[ "$OSTYPE" =~ ^darwin.* ]]; then
local wait="-W1"
fi
ping -q ${wait} -c1 8.8.8.8 &> /dev/null || { echo -e "${BIYellow}OFFLINE${RST}"; f_offline=1; return 1; }
echo -e "${BIGreen}ONLINE${RST}"
}
##############################################################################
# Download required packages from internet
# Globals:
# colors
# f_offline
# Arguments:
# None
# Returns:
# 1 if we are offline
###############################################################################
download () {
echo -e "${IGreen}>>>${RST} Downloading packages for offline installation ..."
$PYTHON -m pip download -r "$PYPE_SETUP_PATH/pypeapp/requirements.txt" -d "$PYPE_SETUP_PATH/vendor/packages"
if [ $? -ne 0 ] ; then
echo -e "${BIYellow}!!!${RST} Download failed"
return 1
fi
return 0
}
##############################################################################
# Copy vendor/bin to local pype env
# Globals:
# PYPE_ENV
# PYPE_SETUP_PATH
# Arguments:
# None
# Returns:
# None
###############################################################################
localize_bin () {
echo -e "${IGreen}>>>${RST} Localizing [ ${BIWhite}vendor/bin${RST} ] ..."
mkdir -p $PYPE_ENV/localized
cp -aR $PYPE_SETUP_PATH/vendor/bin/* $PYPE_ENV/localized/
}
##############################################################################
# Clean pyc files in specified directory
# Globals:
# None
# Arguments:
# Optional path to clean
# Returns:
# None
###############################################################################
clean_pyc () {
path=${1:-$PYPE_SETUP_PATH}
echo -e "${IGreen}>>>${RST} Cleaning pyc at [ ${BIWhite}$path${RST} ] ... \c"
find "$path" -regex '^.*\(__pycache__\|\.py[co]\)$' -delete
echo -e "${BIGreen}DONE${RST}"
}
# -----------------------------------------------------------------------------
# main
# -----------------------------------------------------------------------------
main () {
art
echo -e "${IGreen}***${RST} Welcome to ${BIWhite}Pype${RST}!"
# Clean pyc
if [ "$f_clean" == 1 ] ; then
clean_pyc
echo -e "${ICyan}<<<${RST} Terminating ${IWhite}Pype${RST} ..."
return 0
fi
# Check invalid argument combination
if [ "$f_deploy" == 1 ] ; then
if [ "$f_offline" == 1 ] ; then
echo -e "${BIRed}!!!{$RST} Invalid invocation, cannot deploy in offline mode."
return 1
fi
fi
# Test if python is available and test its version
detect_python || return 1
# Detect git
# used only when deploying or validating deployment
if [ "$f_deploy" == 1 ] || [ "$f_validate" == 1 ] ; then
detect_git || return 1
fi
# Detect mongod in PATHs
# used only when starting local mongodb
if [ "$f_mongodb" == 1 ] ; then
detect_mongo || return 1
fi
# Detect existing venv
echo -e "${IGreen}>>>${RST} Detecting environment ... \c"
needToInstall="0"
# Does directory exist?
if [ -d "$PYPE_ENV" ] ; then
# If so, is it empy?
if [ ! "$(ls -A $PYPE_ENV)" ] ; then
needToInstall="1"
fi
else
needToInstall="1"
fi
if [ "$f_install" == 1 ] ; then
needToInstall="1"
fi
if [ $needToInstall -eq "1" ] ; then
if [ "$f_install" == 1 ] ; then
echo -e "${BIYellow}WILL BE INSTALLED${RST}"
else
echo -e "${BIYellow}NOT FOUND${RST}"
fi
test_offline
if [[ $OSTYPE =~ ^darwin.* ]]; then
if ! have_command_line_tools; then
echo -e "${BIYellow}>>>${RST} We need to install ${IWhite}Xcode Command Line Tools${RST}"
if [ "$_offline" == 1 ] ; then
echo -e "${BIRed}!!!${RST} but you are offline, so we cannot download it. Install it manually or go online and try again"
return 1
fi
echo -e "${IGreen}>>>${RST} Searching online for the Command Line Tools"
# This is taken and modified from Homebrew installation script.
# All credits should go there.
# It seems that we need Xcode command line tools to install dependencies
# via pip on MacOS, like Pillow, etc. Also we need to use them to set
# few things on newer systems (like 10.14 and 10.15) to point to corrent
# location of various header files (zlib, ...)
#
# This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools
clt_placeholder="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
execute_sudo "/usr/bin/touch" "$clt_placeholder"
clt_label_command="/usr/sbin/softwareupdate -l |
grep -B 1 -E 'Command Line Tools' |
awk -F'*' '/^ *\\*/ {print \$2}' |
sed -e 's/^ *Label: //' -e 's/^ *//' |
sort -V |
tail -n1"
clt_label="$(chomp "$(/bin/bash -c "$clt_label_command")")"
if [[ -n "$clt_label" ]]; then
echo -e "${IGreen}>>>${RST} Installing $clt_label"
execute_sudo "/usr/sbin/softwareupdate" "-i" "$clt_label"
execute_sudo "/bin/rm" "-f" "$clt_placeholder"
execute_sudo "/usr/bin/xcode-select" "--switch" "/Library/Developer/CommandLineTools"
fi
else
echo -e "${IGreen}>>>${RST} Fixing SDK paths ..."
export CPATH=`xcrun --show-sdk-path`/usr/include
fi
# Headless install may have failed, so fallback to original 'xcode-select' method
if ! have_command_line_tools && test -t 0; then
echo -e "${IGreen}>>>${RST} Installing the Command Line Tools (expect a GUI popup):"
execute_sudo "/usr/bin/xcode-select" "--install"
echo -e "${BIPurple}___${RST} Press any key when the installation has completed."
getc
execute_sudo "/usr/bin/xcode-select" "--switch" "/Library/Developer/CommandLineTools"
fi
if ! output="$(/usr/bin/xcrun clang 2>&1)" && [[ "$output" == *"license"* ]]; then
echo -e "${BIRed}!!! WARNING:${RST} You have not agreed to the Xcode license."
echo -e "${BIYellow} *${RST} Before running the installer again please agree to the license by opening"
echo -e "${BIYellow} *${RST} ${UCyan}Xcode.app${RST} or running: ${BIWhite}sudo xcodebuild -license${RST}"
return 1
fi
# set icons on Mac
echo -e "${IGreen}>>>${RST} Setting icon on Pype files ..."
for i in $PYPE_SETUP_PATH/launchers/*.command; do
[ -f "$i" ] || break
$PYPE_SETUP_PATH/vendor/fileicon.sh set $i $PYPE_SETUP_PATH/pypeapp/pype.icns
done
$PYPE_SETUP_PATH/vendor/fileicon.sh set $PYPE_SETUP_PATH/pype $PYPE_SETUP_PATH/pypeapp/pype.icns
fi
# install environment
install_environment || return 1
# activate environment
activate_venv $PYPE_ENV || return 1
# install wheel as it is sometimes missing in default venv
echo -e "${IGreen}>>>${RST} Installing wheel ..."
if [ "$_offline" == 1 ] ; then
pip3 install wheel --no-index --find-links "$PYPE_SETUP_PATH/vendor/packages" 2> /dev/null
else
pip3 install wheel 2> /dev/null
fi
# bootstrap pype
bootstrap_pype || return 1
if [[ $OSTYPE =~ ^darwin.* ]]; then
echo -e "${IGreen}>>>${RST} Fixing file permissions ...\c"
current_sudo_user=$(who -m | awk '{print $1;}')
execute_sudo chown -R $current_sudo_user $PYPE_ENV
execute_sudo chown -R $current_sudo_user "/Users/$current_sudo_user/Library/Caches/pip"
echo -e "${BIGreen}DONE${RST}"
fi
else
echo -e "${BIGreen}FOUND${RST} - [${BIWhite} $PYPE_ENV ${RST}]"
activate_venv $PYPE_ENV || return 1
check_environment || return 1
fi
if [ "$f_install" == 1 ] ; then
echo -e "${IGreen}>>>${RST} Checking for and running any post-installation scripts ..."
find "$PYPE_SETUP_PATH/deploy" -name 'post-install.sh' -print0 | xargs -r -0 bash -c
echo -e "${IGreen}***${RST} Installation complete. ${IWhite}Have a nice day!${RST}"
return 0
fi
# Update
if [ "$f_update" == 1 ] ; then
update_requirements || return 1
return 0
fi
# Download
# This will download pip packages to vendor/packages for later offline
# installation and exit
if [ "$f_download" == 1 ] ; then
download || return 1
return 0
fi
# Validate deployment
if [ "$f_validate" == 1 ] ; then
echo -e "${IGreen}>>>${RST} Validating ${BIWhite}Pype${RST} deployment ..."
validate_pype || return 1
echo -e "${BIGreen}>>>${RST} Deployment is ${BIGreen}OK${RST}"
return
fi
# Deploy
if [ "$f_deploy" == 1 ] ; then
test_offline
if [ "$_offline" == 1 ] ; then
# If we are offline, we cannot deploy
echo -e "${BIRed}!!!${RST} Cannot deploy in offline mode."
return 1
fi
# if force set, then re-deploy
if [ "$f_force" == 1 ] ; then
echo -e "${IGreen}>>>${RST} Deploying ${BIWhite}Pype${RST} forcefully ..."
else
echo -e "${IGreen}>>>${RST} Deploying ${BIWhite}Pype${RST} ..."
fi
deploy_pype || return 1
echo -e "${IGreen}>>>${RST} Validating ${BIWhite}Pype${RST} deployment ..."
validate_pype || return 1
echo -e "${BIGreen}>>>${RST} Deployment is ${BIGreen}OK${RST}"
localize_bin || return 1
return
fi
# Localize binaries
if [ "$f_localize" == 1 ] ; then
localize_bin || return 1
return
fi
if [ "$f_macIcons" == 1 ] ; then
if [[ $OSTYPE =~ ^darwin.* ]]; then
echo -e "${IGreen}>>>${RST} Setting icon on Pype files ..."
for i in $PYPE_SETUP_PATH/launchers/*.command; do
[ -f "$i" ] || break
$PYPE_SETUP_PATH/vendor/fileicon.sh set $i $PYPE_SETUP_PATH/pypeapp/pype.icns
done
$PYPE_SETUP_PATH/vendor/fileicon.sh set $PYPE_SETUP_PATH/pype $PYPE_SETUP_PATH/pypeapp/pype.icns
else
echo -e "${BIYellow}***${RST} ${Yellow}Setting files icon can be done only on mac.${RST}"
fi
fi
echo -e "${IGreen}>>>${RST} Checking for and running any pre run scripts ..."
find "$PYPE_SETUP_PATH/deploy" -name 'pre-run.sh' -print0 | xargs -r -0 bash -c
echo -e "${IGreen}>>>${RST} Running ${IWhite}Pype${RST} ..."
$PYTHON -m pypeapp $args || return $?
echo -e "${IPurple}xxx${RST} Finishing up. ${IWhite}Have a nice day!${RST}"
}
return_code=0
main "$args" || return_code=$?
deactivate_venv $PYPE_ENV
exit $return_code