File: install.sh

package info (click to toggle)
pinto 0.14000-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,900 kB
  • sloc: perl: 12,566; sh: 255; makefile: 7
file content (181 lines) | stat: -rwxr-xr-x 6,527 bytes parent folder | download | duplicates (3)
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
#!/bin/bash

##############################################################################
# THIS IS THE PINTO INSTALLER
#
# This bash script will install pinto as a standalone application.
#
# By default, pinto and all of its dependencies will be built into the 
# ~/opt/local/pinto directory.  You can change this location by setting the
# PINTO_HOME environment variable before running this script.
#
# The purpose of a standalone installation is to isolate pinto from whatever
# other Perl modules you may have in your environment.  So if you ever upgrade
# or change those modules, pinto will not be affected.  Nor does installing 
# pinto affect any of the modules your other apps are using.
#
# The most common way to run this installer is like this:
#
#   curl -L http://getpinto.stratopan.com | bash
#
# Or if you prefer to use wget then run this command:
#
#   wget -O - http://getpinto.stratopan.com | bash
#
# After a succesful installation, you'll be instructed on how to amend your
# ~/.profile (or ~/.bashrc, or whatever you prefer) so that pinto runs
# naturally in your everyday shell environment.
#
# All the depndencies for pinto come from a curated repository hosted at
# http://stratopan.com.  That repository contains specific versions of all 
# the modules that pinto needs.  So those may not be the latest versions,
# but they are versions that I know will work (and that's the whole point
# of having a pinto repository anyway).
#
# If this installer doesn't work for you, then you can fallback to installing
# the App::Pinto module from CPAN.  Again, cpanm(1) is really excellent for
# that, but you can use cpan(1) too.  When installing from CPAN, you'll be 
# getting the versions of modules that are in the CPAN index at that moment, 
# which may or may not be 100% compatible with pinto (usually they are, but 
# you never know).
#
# CONFIGURATION
#
# The following environment variables can be used to control the installation:
#
# PINTO_HOME
#
#   Sets the directory where pinto will be installed. 
#   Defaults to $HOME/opt/local/pinto
#
# PINTO_REPO_URL
#
#   Sets the URL of the repository that provides pinto's dependencies
#   Defaults to https://www.stratopan.com/thaljef/OpenSource/pinto-release
#
# PINTO_INSTALLER_AGENT
#
#   Sets the name of the tool that will be used to fetch cpanm.  If set, 
#   it must be either 'curl' or 'wget'.  If not set, the installer will
#   fallback to either 'curl' or 'wget' (in that order) depending on what
#   you already have installed.
#
# PERL_CPANM_OPT
#
#   Sets the default options for cpanm, which is used to install pinto.  This
#   can be useful if you need to specify a certain agent such as lwp, curl,
#   or wget.  See https://metacpan.org/module/cpanm for more details.
#
# Copyright 2013 Jeffrey Ryan Thalhammer <jeff@stratopan.com>
#
##############################################################################

set -ue

#-----------------------------------------------------------------------------
# You can set these variables beforehand to override defaults

PINTO_REPO_URL=${PINTO_REPO_URL:="https://www.stratopan.com/thaljef/OpenSource/pinto-release"}
PINTO_HOME=${PINTO_HOME:="$HOME/opt/local/pinto"}

#-----------------------------------------------------------------------------
# Decide which agent to use.  Set PINTO_INSTALLER_AGENT to override

if  [ -z ${PINTO_INSTALLER_AGENT:-} ]; then

    if type curl > /dev/null 2>&1; then
        PINTO_INSTALLER_AGENT='curl'
    elif type wget > /dev/null 2>&1; then 
        PINTO_INSTALLER_AGENT='wget'
    else
        echo "Must have curl or wget to install pinto"
        exit 1
    fi
fi

#-----------------------------------------------------------------------------
# Bootstrap cpanm

PINTO_CPANM_URL=${PINTO_CPANM_URL:="https://raw.githubusercontent.com/thaljef/Pinto/master/etc/cpanm"}
PINTO_SBIN="$PINTO_HOME/sbin"
PINTO_CPANM_EXE="$PINTO_SBIN/cpanm"

mkdir -p "$PINTO_SBIN"

if   [ $PINTO_INSTALLER_AGENT = 'curl' ]; then
	curl --silent --show-error --location $PINTO_CPANM_URL > "$PINTO_CPANM_EXE"
elif [ $PINTO_INSTALLER_AGENT = 'wget' ]; then 
	wget --no-verbose --output-document - $PINTO_CPANM_URL > "$PINTO_CPANM_EXE"
else
	echo "Invalid PINTO_INSTALLER_AGENT ($PINTO_INSTALLER_AGENT)."
        echo "If set, PINTO_INSTALLER_AGENT must be 'curl' or 'wget'".
        exit 1;
fi

chmod 755 "$PINTO_CPANM_EXE"

#-----------------------------------------------------------------------------
# Do installation

echo "Installing pinto into $PINTO_HOME"

# Workaround for removal of "." from @INC in perl 5.26.0
export PERL_USE_UNSAFE_INC=1

"$PINTO_CPANM_EXE" --notest --quiet --mirror $PINTO_REPO_URL --mirror-only  \
      --local-lib-contained "$PINTO_HOME" --man-pages Pinto

# TODO: send the build log and `perl -V` back for analysis
if [ $? -ne 0 ] ; then echo "Installation failed."; exit 1; fi

#-----------------------------------------------------------------------------
# Remove scripts and man pages that aren't from pinto

(cd "$PINTO_HOME/bin";      ls | grep -iv pinto | xargs rm -f)
(cd "$PINTO_HOME/man/man1"; ls | grep -iv pinto | xargs rm -f)
(cd "$PINTO_HOME/man/man3"; ls | grep -iv pinto | xargs rm -f)

#-----------------------------------------------------------------------------
# Create the etc/ directory

PINTO_ETC="$PINTO_HOME/etc"
mkdir -p "$PINTO_ETC"

#-----------------------------------------------------------------------------
# Write the bash setup file in etc/

PINTO_BASHRC="$PINTO_ETC/bashrc"

cat > "$PINTO_BASHRC" <<END_CONFIG
###        THIS IS A GENERATED FILE -- DO NOT EDIT         ###
export PINTO_HOME="$PINTO_HOME"
export PATH="\$PINTO_HOME/bin:\$PATH"
export MANPATH="\$PINTO_HOME/man:\$MANPATH"

###        PUT YOUR CUSTOMIZATIONS IN \$HOME/.pintorc      ###
if [ -f "\$HOME/.pintorc" ]; then source "\$HOME/.pintorc"; fi
END_CONFIG

#-----------------------------------------------------------------------------
# Display instructions

cat <<END_MSG
pinto has been installed at $PINTO_HOME.  
To activate it, give this command:

  source $PINTO_HOME/etc/bashrc

To make pinto part of your everyday environment, add that 
last command to your ~/.profile or ~/.bashrc file as well.

We want your feedback!  Help us make Pinto better by
writing a review of Pinto at http://cpanratings.perl.org.

Got questions about Pinto?  We have the answers!  Contact
us at team@stratopan.com or on the #pinto channel on IRC.
END_MSG

#-----------------------------------------------------------------------------
# Done

exit 0