-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvsetup
executable file
·90 lines (71 loc) · 1.96 KB
/
envsetup
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
#!/usr/bin/env bash
function ptk_print_env
{
cat <<EOF
============================================
PTK environment:
PTK_HOME=$PTK_HOME
PTK_BIN=$PTK_BIN
PTK_LIB=$PTK_LIB
PATH=$PATH
PERL5LIB=$PERL5LIB
PTK_LOG_LEVEL=$PTK_LOG_LEVEL
============================================
EOF
}
function ptk_update_cpanm
{
mkdir -p $PTK_BIN
curl -L https://cpanmin.us/ -o $PTK_CPANM
chmod +x $PTK_CPANM
}
function ptk_cpanm
{
$PTK_CPANM --mirror http://mirrors.163.com/cpan --mirror http://cpan.cpantesters.org -l $PTK_EXT $@
}
function ptk_update_ext
{
mkdir -p $PTK_EXT
ptk_cpanm -n ExtUtils::MakeMaker && ptk_cpanm -n --installdeps $PTK_HOME && date > $PTK_EXT/.updated
}
# Mac OS does not support GNU "readlink -f", so use Perl instead
function ptk_readlink
{
perl -MCwd -e 'print Cwd::abs_path shift' "$1"
}
if [[ $0 == $BASH_SOURCE ]]; then
echo 'Invoke using "source" please, e.g.'
echo " source $BASH_SOURCE"
else
# PTK home dir, where PTK is deployed
export PTK_HOME=$(dirname $(ptk_readlink $BASH_SOURCE))
export PTK_BIN=$PTK_HOME/bin
export PTK_LIB=$PTK_HOME/lib
# no need to export
PTK_EXT=$PTK_HOME/ext
PTK_CPANM=$PTK_BIN/cpanm
# log level: [debug, info, warn, error, fatal]
export PTK_LOG_LEVEL=info
# deploy the cpanm if not exist
echo "check cpanm"
if [[ ! -f $PTK_CPANM ]]; then
echo "not ready, update cpanm..."
ptk_update_cpanm
fi
# deploy the ext if not exist or hasn't been fully updated
echo "check ext"
if [[ ! -d $PTK_EXT || ! -f $PTK_EXT/.updated ]]; then
echo "not ready, update ext..."
ptk_update_ext
fi
# setup the local lib
echo "set up local::lib"
eval "$(perl -I$PTK_EXT/lib/perl5 -Mlocal::lib=--shelltype=bourne,$PTK_EXT)"
if [[ ! $PATH =~ $PTK_BIN: ]]; then
export PATH=$PTK_BIN:$PATH
fi
if [[ ! $PERL5LIB =~ $PTK_LIB: ]]; then
export PERL5LIB=$PTK_LIB:$PERL5LIB
fi
ptk_print_env
fi