-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcpanm-install
executable file
·97 lines (75 loc) · 2.18 KB
/
cpanm-install
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
#!/bin/bash
# Setup home directory based perl environment and cpanm
set -e
existing_cpanm=$(type -p cpanm || true)
if [[ $existing_cpanm ]] ; then
if [[ $1 != "--force" ]] ; then
echo "Found existing cpanm ($existing_cpanm) - use --force if you are sure" >&2
exit 1
fi
fi
if [[ ! $HOME =~ ^/ ]] ; then
echo "Please specify a home starting with a /" >&2
exit 1
fi
dst=$HOME/perl5
lib=$dst/lib/perl5
bin=$dst/bin
local_lib=$HOME/perldev/lib
local_bin=$HOME/perldev/bin
bashrc=$HOME/.bashrc
bashrc_d=$HOME/.bashrc.d
cpan_dir=$HOME/.cpan
cpanm_dir=$HOME/.cpanm
tmp=$(mktemp -d)
cd $tmp
echo
echo "Using temp dir: $tmp"
echo
echo "downloading cpanm..."
wget --no-check-certificate -q http://xrl.us/cpanm
if [[ -d $cpan_dir ]] ; then
echo "Backing up old $cpan_dir to $tmp/..."
mv $cpan_dir $tmp/
fi
if [[ -d $cpanm_dir ]] ; then
echo "Backing up old $cpanm_dir to $tmp/..."
mv $cpanm_dir $tmp/
fi
chmod +x cpanm
mkdir -p $bin
mv cpanm $bin/
mkdir -p $local_lib $local_bin
echo "updating $bashrc..."
add_msg="# added by cpanm-install"
echo "export PERL5LIB=$local_lib:$lib $add_msg" > bashrc
echo "export PATH=\$PATH:$local_bin:$bin $add_msg" >> bashrc
echo "alias cpanm='cpanm -nq --local-lib $dst' $add_msg" >> bashrc
echo 'alias cpan="(echo use cpanm ; exit 1)" '"$add_msg" >> bashrc
if [[ -d $bashrc_d ]] ; then
echo '### AUTOMATICALLY GENERATED FILE - DONT EDIT! '"$add_msg" >> bashrc
echo "adding $bashrc_d/perl..."
cp bashrc $bashrc_d/0_perl
else
if [[ ! -e "$bashrc" ]] ; then
echo "$bashrc does not exist - creating new one..."
touch $bashrc
fi
(cat $bashrc ; echo) | grep -v "$add_msg" >> bashrc
cp bashrc $bashrc
fi
echo
echo "Perl environment setup complete - please review the changes."
echo
echo "Use 'cpanm ModuleName' to install modules from cpan."
echo "Cpan modules will be installed to your local directory: $dst."
echo
echo "Save your own modules to $local_lib."
echo "Save your own executables to $local_bin."
echo
echo "To run perl script as crons add these lines to your crontab:"
echo "SHELL=/bin/bash"
echo "BASH_ENV=$bashrc"
echo
echo "Please logout and back in for the changes to take effect."
echo