-
Notifications
You must be signed in to change notification settings - Fork 2
/
install-pyrun
executable file
·819 lines (752 loc) · 23.3 KB
/
install-pyrun
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
#!/bin/bash
#
# Install eGenix PyRun in a given target directory.
#
HELP="
Install eGenix PyRun in a given target directory.
USAGE:
install-pyrun [options] targetdir
OPTIONS:
-m or --minimal
install eGenix PyRun only (no setuptools and pip)
-l of --log
log installation to targetdir/pyrun-installation.log
-q or --quiet
quiet installation
-r or --requirements
have pip install the given requirements (only works
if pip is installed as part of the pyrun installation)
--python=3.12
install PyRun for Python version 2.7, 3.8 - 3.12 (default)
--python-unicode=ucs2
install PyRun for Python Unicode version
ucs2 (default for Python 2) or ucs4 (default for Python 3)
--pyrun=2.6.0
install PyRun version 2.6.0 (default)
--platform=linux-i686
install PyRun for the given platform; this is usually
auto-detected
--platform-list
list available platform strings
--pyrun-distribution=pyrun.tgz
use the given PyRun distribution file; this overrides
all other distribution selection parameters
--pyrun-executable=pyrun
symlink to and use an alternative name for the PyRun
executable
--setuptools-distribution=setuptools.tgz
use the given setuptools distribution file instead of
downloading it from PyPI
--setuptools-version=<version>
install setuptools <version>; use
--setuptools-version=latest to automatically find the
latest version on PyPI (default)
--distribute-distribution=distribute.tgz
alias for --setuptools-distribution
--pip-distribution=pip.tgz
use the given pip distribution file instead of
downloading it from PyPI
--pip-version=<version>
install the pip <version>; use --pip-version=latest
to automatically find the latest version on PyPI (default)
--help
show this text
--version
show the script version
--copyright
show copyright
--debug
enable debug output
--disable-certificate-checks
disable certificate checks when downloading packages;
this should normally not be needed
Without options, the script installs eGenix PyRun, setuptools and pip
in targetdir. If no local versions of setuptools or pip are found, the
tools are downloaded from pypi.org.
"
COPYRIGHT='
Copyright (c) 1997-2000, IKDS Marc-Andre Lemburg; mailto:[email protected]
Copyright (c) 2000-2024, eGenix.com Software GmbH; mailto:[email protected]
All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
'
# Script version
VERSION=1.7.1
# Generate debug output ?
DEBUG=0
# List of available platform binaries
PLATFORM_LIST="\
linux-x86_64
linux-i686
linux-armv6l
freebsd-10.3-RELEASE-amd64
freebsd-10.3-RELEASE-i386
macosx-10.4-fat
macosx-10.5-x86_64
"
### Configuration
# Select Python version (major.minor)
PYTHON_VERSION=3.12
# Select Python Unicode version (ucs2 or ucs4 depending on Python version)
PYTHON_UNICODE_VERSION=
# Select PyRun version (major.minor.patch)
PYRUN_VERSION=2.6.0
# Platform string on the PyRun binary distribution (usually
# auto-detected, see below)
PLATFORM=
# PyRun distribution file. This may contain path information and is
# set from the above configuration parameters, if not given explicitly
# via --pyrun-distribution=
PYRUN_DISTRIBUTION=
# Local PyRun distribution directory to search in
LOCAL_PYRUN_DISTRIBUTION_DIR=/downloads/egenix
# Local PyRun executable name to use
PYRUN_EXECUTABLE=pyrun
#PYRUN_EXECUTABLE=python
# Local setuptools distribution to search for
#SETUPTOOLS_VERSION=15.2
SETUPTOOLS_VERSION=latest
LOCAL_SETUPTOOLS_DISTRIBUTION_DIR=/downloads/python/setuptools
# Local pip distribution to search for
#PIP_VERSION=1.5.6
PIP_VERSION=latest
LOCAL_PIP_DISTRIBUTION_DIR=/downloads/python/pip
# pip requirements to install
PIP_REQUIREMENTS=
### Parse options
INSTALL_SETUPTOOLS=1
INSTALL_PIP=1
LOG_INSTALLATION=0
RUN_SILENT=0
VERBOSITY=0
DISABLE_CERTIFICATE_CHECKS=0
args=("$@")
nargs=${#args[@]}
#echo "Found $nargs args"
for (( i=0; i<$nargs; i++ )); do
arg="${args[i]}"
#echo "Parsing arg $i: '$arg'"
while [ -n $arg ]; do
case $arg in
- )
break
;;
# Short options (can be comined, e.g. -mq)
-m* )
INSTALL_SETUPTOOLS=0
INSTALL_PIP=0
arg="-"${arg:2}
;;
-q* )
RUN_SILENT=1
arg="-"${arg:2}
;;
-l* )
LOG_INSTALLATION=1
arg="-"${arg:2}
;;
-r* )
# Note: We use eval here to deal with tilde expansions
# and the like
i=$((i+1))
eval PIP_REQUIREMENTS="${args[i]}"
arg="-"${arg:2}
;;
-h* )
# Note: The quotes are important to make sure the
# newlines are interpreted correctly
echo "$HELP"
exit 0
;;
# Long options
--minimal )
INSTALL_SETUPTOOLS=0
INSTALL_PIP=0
break
;;
--quiet )
RUN_SILENT=1
break
;;
--log )
LOG_INSTALLATION=1
break
;;
--requirements=* )
# Note: We use eval here to deal with tilde expansions
# and the like
eval PIP_REQUIREMENTS="${arg:15}"
break
;;
--help )
# Note: The quotes are important to make sure the
# newlines are interpreted correctly
echo "$HELP"
exit 0
;;
# Long-only options
--python=* )
PYTHON_VERSION=${arg:9}
break
;;
--python-unicode=* )
PYTHON_UNICODE_VERSION=${arg:17}
break
;;
--pyrun=* )
PYRUN_VERSION=${arg:8}
break
;;
--platform=* )
PLATFORM=${arg:11}
break
;;
--platform-list )
echo "Available platform strings:"
echo "---------------------------"
echo "$PLATFORM_LIST"
exit 0
break
;;
--pyrun-distribution=* )
# Note: We use eval here to deal with tilde expansions
# and the like
eval PYRUN_DISTRIBUTION="${arg:21}"
break
;;
--pyrun-executable=* )
# Note: We use eval here to deal with tilde expansions
# and the like
eval PYRUN_EXECUTABLE="${arg:19}"
break
;;
--setuptools-distribution=*|--distribute-distribution=* )
# Note: We use eval here to deal with tilde expansions
# and the like
eval SETUPTOOLS_DISTRIBUTION="${arg:26}"
break
;;
--setuptools-version=* )
SETUPTOOLS_VERSION=${arg:21}
break
;;
--pip-distribution=* )
# Note: We use eval here to deal with tilde expansions
# and the like
eval PIP_DISTRIBUTION="${arg:19}"
break
;;
--pip-version=* )
PIP_VERSION=${arg:14}
break
;;
--disable-certificate-checks )
DISABLE_CERTIFICATE_CHECKS=1
break
;;
--version )
echo "install-pyrun $VERSION"
exit 0
;;
--copyright )
echo "$COPYRIGHT"
exit 0
;;
--debug )
DEBUG=1
break
;;
# Unknown option
-* )
echo "Unknown option: $arg"
exit 1
;;
# First non-option argument
* )
# Note: We use eval here to deal with tilde expansions
# and the like
eval INSTALLATION_DIR="$arg"
break 2
;;
esac
done
done
# Installation directory
if [ -z "$INSTALLATION_DIR" ]; then
echo "$HELP"
exit 1
fi
### Helpers
# Current work dir
CWD=`pwd`
# Tools
TAR=tar
UNZIP=unzip
LN=ln
MKDIR=mkdir
CURL=$(command -v curl)
CURL_OPTIONS="-Ssf"
CURL_FILE_OPTIONS="-O"
CURL_STDOUT_OPTIONS="-o -"
WGET=$(command -v wget)
WGET_OPTIONS=
WGET_FILE_OPTIONS=
WGET_STDOUT_OPTIONS="-O -"
RM=rm
ECHO=echo
# Detect platform, if not given
if [ -z "$PYTHON_UNICODE_VERSION" ]; then
if [[ "$PYTHON_VERSION" < "3" ]]; then
# Python 2 default
PYTHON_UNICODE_VERSION="ucs2"
else
# Python 3 default
PYTHON_UNICODE_VERSION="ucs4"
fi
fi
# Certificate checks
if (( $DISABLE_CERTIFICATE_CHECKS )); then
CURL_OPTIONS="-k $CURL_OPTIONS"
WGET_OPTIONS="--no-check-certificate $WGET_OPTIONS"
fi
# Convert to absolute path
case "$INSTALLATION_DIR" in
/*) ;;
*) INSTALLATION_DIR=$CWD/$INSTALLATION_DIR
esac
# Log file
if (( $LOG_INSTALLATION )); then
LOG_FILE=$INSTALLATION_DIR/pyrun-installation.log
else
LOG_FILE=/dev/null
fi
if (( $RUN_SILENT )); then
LOG_FILE=/dev/null
ECHO=true
fi
# Fetch URL tool
if [ -e "$CURL" ]; then
FETCHURL="$CURL $CURL_OPTIONS $CURL_FILE_OPTIONS "
READURL="$CURL $CURL_OPTIONS $CURL_STDOUT_OPTIONS "
elif [ -e "$WGET" ]; then
FETCHURL="$WGET $WGET_OPTIONS $WGET_FILE_OPTIONS "
READURL="$WGET $WGET_OPTIONS $WGET_STDOUT_OPTIONS "
else
echo "Could not find curl or wget. Please consider installing one of those tools."
FETCHURL=
READURL=
fi
# Detect platform, if not given
if [ -z "$PLATFORM" ]; then
PLATFORM_SYSTEM=`uname -s`
PLATFORM_PROCESSOR=`uname -p`
if [[ "$PLATFORM_PROCESSOR" -eq "unknown" ]]; then
PLATFORM_PROCESSOR=`uname -m`
fi
# When updating this list, please also update the PLATFORM_LIST
# variable further up.
case "$PLATFORM_SYSTEM $PLATFORM_PROCESSOR" in
Linux\ x86_64 )
PLATFORM=linux-x86_64
;;
Linux\ i?86 )
PLATFORM=linux-i686
;;
Linux\ armv6l )
# Raspberry Pi
PLATFORM=linux-armv6l
;;
FreeBSD\ amd64 )
PLATFORM=freebsd-8.3-RELEASE-p3-amd64
;;
FreeBSD\ i386 )
PLATFORM=freebsd-8.3-RELEASE-p3-i386
;;
Darwin\ powerpc )
PLATFORM=macosx-10.4-fat
;;
Darwin\ i386 )
OS_VERSION=`uname -r`
if (( ${OS_VERSION%%.*} < 10 )); then
# Leopard and earlier default to 32-bit applications
PLATFORM=macosx-10.4-fat
else
# Snow Leopard and later can run 64-bit applications
PLATFORM=macosx-10.5-x86_64
fi
;;
Darwin\ x86_64 )
PLATFORM=macosx-10.5-x86_64
;;
* )
echo "Unknown platform \"$PLATFORM_SYSTEM $PLATFORM_PROCESSOR\". Please set manually using --platform=..."
exit 1
;;
esac
fi
# Double check Python compatibility
#
# Python 2.7 support was dropped from setuptools in version 45.0.0
# and from pip in version
#
if [ "$PYTHON_VERSION" == "2.7" ]; then
# setuptools dropped Python 2.7 support in setuptools 45.0, so
# force to use the last compatible setuptools version
if [[ "$SETUPTOOLS_VERSION" > "44.1.1" ]]; then
echo "WARNING: setuptools $SETUPTOOLS_VERSION is not compatible with Python 2.7; using setuptools 44.1.1" 2>&1 | tee -a $LOG_FILE
SETUPTOOLS_VERSION="44.1.1"
fi
# pip dropped Python 2.7 support in pip 21.0, so force to use the last
# compatible pip version
if [[ "$PIP_VERSION" > "21.0" ]]; then
echo "WARNING: pip $PIP_VERSION is not compatible with Python 2.7; using pip 20.3.3" 2>&1 | tee -a $LOG_FILE
PIP_VERSION="20.3.3"
fi
fi
if [ "$PYTHON_VERSION" == "3.8" ]; then
# setuptools dropped Python 3.8 support in setuptools 75.4.0, so
# force to use the last compatible setuptools version
if [[ "$SETUPTOOLS_VERSION" > "75.4.0" || "$SETUPTOOLS_VERSION" == "latest" ]]; then
echo "WARNING: setuptools $SETUPTOOLS_VERSION is not compatible with Python 3.8; using setuptools 75.3.0" 2>&1 | tee -a $LOG_FILE
SETUPTOOLS_VERSION="75.3.0"
fi
fi
# eGenix PyRun distribution to use
if [ -z "$PYRUN_DISTRIBUTION" ]; then
PYRUN_DISTRIBUTION=egenix-pyrun-$PYRUN_VERSION-py${PYTHON_VERSION}_$PYTHON_UNICODE_VERSION-$PLATFORM.tgz
fi
# Local distribution file name (use PYRUN_DISTRIBUTION if it exists,
# fall back to LOCAL_PYRUN_DISTRIBUTION_DIR otherwise)
if [ -e $PYRUN_DISTRIBUTION ]; then
LOCAL_PYRUN_DISTRIBUTION=$PYRUN_DISTRIBUTION
else
LOCAL_PYRUN_DISTRIBUTION=$LOCAL_PYRUN_DISTRIBUTION_DIR/$PYRUN_DISTRIBUTION
fi
# Convert to absolute path
case "$LOCAL_PYRUN_DISTRIBUTION" in
/*) ;;
*) LOCAL_PYRUN_DISTRIBUTION=$CWD/$LOCAL_PYRUN_DISTRIBUTION
esac
# Remote distribution URL (this is only used in case no local
# distribution file can be found)
REMOTE_PYRUN_DISTRIBUTION=https://downloads.egenix.com/python/$PYRUN_DISTRIBUTION
# setuptools package on PyPI
SETUPTOOLS_JSON_URL="https://pypi.org/pypi/setuptools/json"
SETUPTOOLS_RE="https://files.pythonhosted.org/packages/[^\"]+/setuptools-[0-9\.]+(\.tar\.gz|\.zip)"
# setuptools distribution to use
if [ -z "$SETUPTOOLS_DISTRIBUTION" ]; then
SETUPTOOLS_DISTRIBUTION=setuptools-$SETUPTOOLS_VERSION.tar.gz
fi
# Local distribution file name for setuptools
if [ -e $SETUPTOOLS_DISTRIBUTION ]; then
LOCAL_SETUPTOOLS_DISTRIBUTION=$SETUPTOOLS_DISTRIBUTION
else
LOCAL_SETUPTOOLS_DISTRIBUTION=$LOCAL_SETUPTOOLS_DISTRIBUTION_DIR/$SETUPTOOLS_DISTRIBUTION
fi
# Convert to absolute path
case "$LOCAL_SETUPTOOLS_DISTRIBUTION" in
/*) ;;
*) LOCAL_SETUPTOOLS_DISTRIBUTION=$CWD/$LOCAL_SETUPTOOLS_DISTRIBUTION
esac
# pip package on PyPI
PIP_JSON_URL="https://pypi.org/pypi/pip/json"
PIP_RE="https://files.pythonhosted.org/packages/[^\"]+/pip-[0-9\.]+(\.tar\.gz|\.zip)"
# pip distribution to use
if [ -z "$PIP_DISTRIBUTION" ]; then
PIP_DISTRIBUTION=pip-$PIP_VERSION.tar.gz
fi
# Local distribution file name for pip
if [ -e $PIP_DISTRIBUTION ]; then
LOCAL_PIP_DISTRIBUTION=$PIP_DISTRIBUTION
else
LOCAL_PIP_DISTRIBUTION=$LOCAL_PIP_DISTRIBUTION_DIR/$PIP_DISTRIBUTION
fi
# Convert to absolute path
case "$LOCAL_PIP_DISTRIBUTION" in
/*) ;;
*) LOCAL_PIP_DISTRIBUTION=$CWD/$LOCAL_PIP_DISTRIBUTION
esac
# Convert PIP_REQUIREMENTS to absolute path, if given
case "$PIP_REQUIREMENTS" in
"") ;;
/*) ;;
*) PIP_REQUIREMENTS=$CWD/$PIP_REQUIREMENTS
esac
# Debug output
if (( DEBUG )); then
$ECHO "Using the following PyRun installation settings:"
$ECHO " PYRUN_VERSION=${PYRUN_VERSION}"
$ECHO " PYTHON_VERSION=${PYTHON_VERSION}"
$ECHO " PYTHON_UNICODE_VERSION=${PYTHON_UNICODE_VERSION}"
$ECHO " PYRUN_DISTRIBUTION=${PYRUN_DISTRIBUTION}"
$ECHO " LOCAL_PYRUN_DISTRIBUTION=${LOCAL_PYRUN_DISTRIBUTION}"
$ECHO " REMOTE_PYRUN_DISTRIBUTION=${REMOTE_PYRUN_DISTRIBUTION}"
$ECHO " SETUPTOOLS_DISTRIBUTION=${SETUPTOOLS_DISTRIBUTION}"
$ECHO " SETUPTOOLS_VERSION=${SETUPTOOLS_VERSION}"
$ECHO " SETUPTOOLS_JSON_URL=${SETUPTOOLS_JSON_URL}"
$ECHO " LOCAL_SETUPTOOLS_DISTRIBUTION=${LOCAL_SETUPTOOLS_DISTRIBUTION}"
$ECHO " PIP_VERSION=${PIP_VERSION}"
$ECHO " PIP_DISTRIBUTION=${PIP_DISTRIBUTION}"
$ECHO " PIP_JSON_URL=${PIP_JSON_URL}"
$ECHO " LOCAL_PIP_DISTRIBUTION=${LOCAL_PIP_DISTRIBUTION}"
$ECHO " PIP_REQUIREMENTS=${PIP_REQUIREMENTS}"
$ECHO " INSTALLATION_DIR=${INSTALLATION_DIR}"
$ECHO " FETCHURL=${FETCHURL}"
fi
### Installation
# Run installation in the INSTALLATION_DIR
$MKDIR -p $INSTALLATION_DIR
cd $INSTALLATION_DIR
touch $LOG_FILE
# Install PyRun
if [ ! -e $LOCAL_PYRUN_DISTRIBUTION ]; then
$ECHO "Downloading eGenix PyRun ..." 2>&1 | tee -a $LOG_FILE
if (( DEBUG )); then
$ECHO "(using $FETCHURL)" >> $LOG_FILE 2>&1
fi
$FETCHURL $REMOTE_PYRUN_DISTRIBUTION >> $LOG_FILE 2>&1
rc=$?
if (( $rc )); then
echo "Failed to download $REMOTE_PYRUN_DISTRIBUTION" 2>&1 | tee -a $LOG_FILE
exit $rc
fi
$ECHO "" >> $LOG_FILE 2>&1
$ECHO "Installing eGenix PyRun ..." 2>&1 | tee -a $LOG_FILE
$TAR -x -v -z -f $PYRUN_DISTRIBUTION >> $LOG_FILE 2>&1
rc=$?
if (( $rc )); then
echo "Failed to extract $PYRUN_DISTRIBUTION" 2>&1 | tee -a $LOG_FILE
exit $rc
fi
$RM -f $PYRUN_DISTRIBUTION
else
$ECHO "Installing eGenix PyRun ..." 2>&1 | tee -a $LOG_FILE
$ECHO "extracting files from $LOCAL_PYRUN_DISTRIBUTION" >> $LOG_FILE 2>&1
$TAR -x -v -z -f $LOCAL_PYRUN_DISTRIBUTION >> $LOG_FILE 2>&1
rc=$?
if (( $rc )); then
echo "Could not extract $LOCAL_PYRUN_DISTRIBUTION" 2>&1 | tee -a $LOG_FILE
exit $rc
fi
fi
$ECHO "" >> $LOG_FILE 2>&1
# Add symlink to an alternative name
if [ "$PYRUN_EXECUTABLE" != "pyrun" ]; then
$ECHO "adding symlink to from bin/pyrun to bin/$PYRUN_EXECUTABLE" >> $LOG_FILE 2>&1
$LN -sf pyrun bin/$PYRUN_EXECUTABLE >> $LOG_FILE 2>&1
$ECHO "" >> $LOG_FILE 2>&1
fi
#
# TODO: Replace this logic with the https://bootstrap.pypa.io/get-pip.py
# helper script
#
# Install setuptools
if (( $INSTALL_SETUPTOOLS )); then
if [ ! -e $LOCAL_SETUPTOOLS_DISTRIBUTION ]; then
# Get package URLs
SETUPTOOLS_URLS=$( \
$READURL -q ${SETUPTOOLS_JSON_URL} | \
egrep -o ${SETUPTOOLS_RE} )
if [ -z "$SETUPTOOLS_URLS" ]; then
echo "Could not find setuptools on PyPI" 2>&1 | tee -a $LOG_FILE
exit $rc
fi
if (( DEBUG )); then
$ECHO "Available setuptools packages:"
$ECHO "${SETUPTOOLS_URLS}"
SETUPTOOLS_VERSIONS=$( \
echo "$SETUPTOOLS_URLS" | \
egrep -o ${SETUPTOOLS_RE} | \
sed -r -e 's/http[^ ]+-//g' -e 's/\.tar.gz|\.zip//g' | \
sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr )
$ECHO "Available setuptools versions:"
$ECHO "${SETUPTOOLS_VERSIONS}"
fi
if [ "$SETUPTOOLS_VERSION" == "latest" ]; then
# Find the URL of the latest setuptools distribution file
$ECHO "Installing latest setuptools from PyPI ..." 2>&1 | tee -a $LOG_FILE
SETUPTOOLS_VERSION=$( \
echo "$SETUPTOOLS_URLS" | \
egrep -o ${SETUPTOOLS_RE} | \
sed -r -e 's/http[^ ]+-//g' -e 's/\.tar\.gz|\.zip//g' | \
sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr | \
head -n 1 )
$ECHO "Found latest version $SETUPTOOLS_VERSION" 2>&1 | tee -a $LOG_FILE
else
$ECHO "Installing setuptools $SETUPTOOLS_VERSION from PyPI ..." 2>&1 | tee -a $LOG_FILE
fi
FETCH_SETUPTOOLS_URL=$( \
echo "$SETUPTOOLS_URLS" | \
egrep -m 1 -o "http.+setuptools-${SETUPTOOLS_VERSION}(\.tar\.gz|\.zip)" )
$ECHO "Downloading setuptools from $FETCH_SETUPTOOLS_URL ..." >> $LOG_FILE 2>&1
if (( DEBUG )); then
$ECHO "(using $FETCHURL)" >> $LOG_FILE 2>&1
fi
$FETCHURL $FETCH_SETUPTOOLS_URL >> $LOG_FILE 2>&1
rc=$?
if (( $rc )); then
echo "Failed to download $FETCH_SETUPTOOLS_URL" 2>&1 | tee -a $LOG_FILE
exit $rc
fi
$ECHO "Extracting and installing setuptools ..." >> $LOG_FILE 2>&1
SETUPTOOLS_FILE=${FETCH_SETUPTOOLS_URL##*/}
if [[ "$SETUPTOOLS_FILE" =~ .+\.tar\.gz ]]; then
$TAR -x -v -z -f $SETUPTOOLS_FILE >> $LOG_FILE 2>&1
SETUPTOOLS_DIR=${SETUPTOOLS_FILE%.tar.gz}
elif [[ "$SETUPTOOLS_FILE" =~ .+\.zip ]]; then
echo "$UNZIP -o $SETUPTOOLS_FILE >> $LOG_FILE 2>&1"
$UNZIP -o $SETUPTOOLS_FILE >> $LOG_FILE 2>&1
SETUPTOOLS_DIR=${SETUPTOOLS_FILE%.zip}
else
echo "*** Unsupported file format: $SETUPTOOLS_FILE"
exit 1
fi
cd $SETUPTOOLS_DIR
../bin/$PYRUN_EXECUTABLE setup.py install >> $LOG_FILE 2>&1
rc=$?
if (( $rc )); then
echo "Failed to install setuptools" 2>&1 | tee -a $LOG_FILE
exit $rc
fi
cd ..
$RM -rf setuptools* >> $LOG_FILE 2>&1
$ECHO "" >> $LOG_FILE 2>&1
else
$ECHO "Installing local setuptools $SETUPTOOLS_VERSION ..." 2>&1 | tee -a $LOG_FILE
$ECHO "extracting files from $LOCAL_SETUPTOOLS_DISTRIBUTION" >> $LOG_FILE 2>&1
$TAR -x -v -z -f $LOCAL_SETUPTOOLS_DISTRIBUTION >> $LOG_FILE 2>&1
rc=$?
if (( $rc )); then
echo "Could not extract $LOCAL_SETUPTOOLS_DISTRIBUTION" 2>&1 | tee -a $LOG_FILE
exit $rc
fi
cd setuptools-*
../bin/$PYRUN_EXECUTABLE setup.py install >> $LOG_FILE 2>&1
rc=$?
cd ..
if (( $rc )); then
echo "Failed to install setuptools" 2>&1 | tee -a $LOG_FILE
exit $rc
fi
$RM -rf setuptools-* >> $LOG_FILE 2>&1
$ECHO "" >> $LOG_FILE 2>&1
fi
fi
# Install pip
if (( $INSTALL_PIP )); then
if [ ! -e $LOCAL_PIP_DISTRIBUTION ]; then
# Get package URLs
PIP_URLS=$( \
$READURL -q ${PIP_JSON_URL} | \
egrep -o ${PIP_RE} )
if [ -z "$PIP_URLS" ]; then
echo "Could not find pip on PyPI" 2>&1 | tee -a $LOG_FILE
exit $rc
fi
if (( DEBUG )); then
$ECHO "Available pip packages:"
$ECHO "${PIP_URLS}"
PIP_VERSIONS=$( \
echo "$PIP_URLS" | \
egrep -o ${PIP_RE} | \
sed -r -e 's/http[^ ]+-//g' -e 's/\.tar.gz|\.zip//g' | \
sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr )
$ECHO "Available pip versions:"
$ECHO "${PIP_VERSIONS}"
fi
if [ "$PIP_VERSION" == "latest" ]; then
# Find the URL of the latest pip distribution file
$ECHO "Installing latest pip from PyPI ..." 2>&1 | tee -a $LOG_FILE
PIP_VERSION=$( \
echo "$PIP_URLS" | \
egrep -o ${PIP_RE} | \
sed -r -e 's/http[^ ]+-//g' -e 's/\.tar\.gz|\.zip//g' | \
sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr | \
head -n 1 )
$ECHO "Found latest version $PIP_VERSION" 2>&1 | tee -a $LOG_FILE
else
$ECHO "Installing pip $PIP_VERSION from PyPI ..." 2>&1 | tee -a $LOG_FILE
fi
FETCH_PIP_URL=$( \
echo "$PIP_URLS" | \
egrep -m 1 -o "http.+pip-${PIP_VERSION}(\.tar\.gz|\.zip)" )
$ECHO "Downloading pip from $FETCH_PIP_URL ..." >> $LOG_FILE 2>&1
if (( DEBUG )); then
$ECHO "(using $FETCHURL)" >> $LOG_FILE 2>&1
fi
$FETCHURL $FETCH_PIP_URL >> $LOG_FILE 2>&1
rc=$?
if (( $rc )); then
echo "Failed to download $FETCH_PIP_URL" 2>&1 | tee -a $LOG_FILE
exit $rc
fi
$ECHO "Extracting and installing pip ..." >> $LOG_FILE 2>&1
PIP_FILE=${FETCH_PIP_URL##*/}
if [[ "$PIP_FILE" =~ .+\.tar\.gz ]]; then
$TAR -x -v -z -f $PIP_FILE >> $LOG_FILE 2>&1
PIP_DIR=${PIP_FILE%.tar.gz}
elif [[ "$PIP_FILE" =~ .+\.zip ]]; then
echo "$UNZIP -o $PIP_FILE >> $LOG_FILE 2>&1"
$UNZIP -o $PIP_FILE >> $LOG_FILE 2>&1
PIP_DIR=${PIP_FILE%.zip}
else
echo "*** Unsupported file format: $PIP_FILE"
exit 1
fi
cd $PIP_DIR
if [ ! -e setup.py ]; then
echo "from setuptools import setup; setup()" > setup.py
fi
../bin/$PYRUN_EXECUTABLE setup.py install >> $LOG_FILE 2>&1
rc=$?
if (( $rc )); then
echo "Failed to install pip" 2>&1 | tee -a $LOG_FILE
exit $rc
fi
cd ..
$RM -rf pip* >> $LOG_FILE 2>&1
$ECHO "" >> $LOG_FILE 2>&1
else
$ECHO "Installing local pip $PIP_VERSION ..." 2>&1 | tee -a $LOG_FILE
$ECHO "extracting files from $LOCAL_PIP_DISTRIBUTION" >> $LOG_FILE 2>&1
$TAR -x -v -z -f $LOCAL_PIP_DISTRIBUTION >> $LOG_FILE 2>&1
rc=$?
if (( $rc )); then
echo "Could not extract $LOCAL_PIP_DISTRIBUTION" 2>&1 | tee -a $LOG_FILE
exit $rc
fi
cd pip-*
if [ ! -e setup.py ]; then
echo "from setuptools import setup; setup()" > setup.py
fi
../bin/$PYRUN_EXECUTABLE setup.py install >> $LOG_FILE 2>&1
rc=$?
cd ..
if (( $rc )); then
echo "Failed to install pip" 2>&1 | tee -a $LOG_FILE
exit $rc
fi
$RM -rf pip-* >> $LOG_FILE 2>&1
$ECHO "" >> $LOG_FILE 2>&1
fi
# Support for -r switch
if [ ! -z "$PIP_REQUIREMENTS" ]; then
$ECHO "Installing pip requirements $PIP_REQUIREMENTS ..." 2>&1 | tee -a $LOG_FILE
bin/pip install -r $PIP_REQUIREMENTS >> $LOG_FILE 2>&1
fi
fi
# Finished
cd ..
$ECHO ""
$ECHO "eGenix PyRun was installed in $INSTALLATION_DIR"
$ECHO ""
$ECHO "To run eGenix PyRun, use $INSTALLATION_DIR/bin/$PYRUN_EXECUTABLE"
$ECHO ""