-
Notifications
You must be signed in to change notification settings - Fork 8
/
perl-install
executable file
·89 lines (73 loc) · 2.04 KB
/
perl-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
#!/bin/bash
set -eu
die() {
echo "$1" >&2
exit 1
}
if [[ $# -ne 1 ]] || [[ $1 = "-h" ]] || [[ $1 = "--help" ]]; then
die "Usage:
perl-install INSTALL_DIR # install latest perl to INSTALL_DIR
perl-install --print-version # print latest perl version, and exit"
fi
PRINT_VERSION=NO
if [[ $1 = "--print-version" ]]; then
PRINT_VERSION=YES
fi
_OS=$(uname -s | tr '[:upper:]' '[:lower:]')
_ARCH=$(uname -m)
if [[ $_ARCH = x86_64 ]]; then
_ARCH=amd64
fi
if [[ $_ARCH = aarch64 ]]; then
_ARCH=arm64
fi
if type curl &>/dev/null; then
HTTP_GET=curl
HTTP_GET_OPTION='-fsSL'
elif type wget &>/dev/null; then
HTTP_GET=wget
HTTP_GET_OPTION='-q -O -'
else
die 'Cannot find `curl` nor `wget`'
fi
LATEST_LINE=$($HTTP_GET $HTTP_GET_OPTION https://raw.githubusercontent.com/skaji/relocatable-perl/main/releases.csv | (\grep -m 1 ,$_OS,$_ARCH,; cat >/dev/null))
if [[ -z $LATEST_LINE ]]; then
die "Failed to determine latest perl version"
fi
LATEST_VERSION=$(echo $LATEST_LINE | \cut -d, -f1)
LATEST_URL=$(echo $LATEST_LINE | \cut -d, -f5)
if [[ $PRINT_VERSION = "YES" ]]; then
echo $LATEST_VERSION
exit
fi
TAR_CMD=gtar
if ! type $TAR_CMD &>/dev/null; then
TAR_CMD=tar
if ! type $TAR_CMD &>/dev/null; then
die 'Cannot find `tar` command'
fi
fi
TAR_OPTION=xzf
TAR_SUFFIX=tar.gz
if type xz &>/dev/null; then
TAR_OPTION=xJf
TAR_SUFFIX=tar.xz
fi
INSTALL_DIR=$1
if [[ -d $INSTALL_DIR ]]; then
[[ -w $INSTALL_DIR ]] || die "You don't have write permission to $INSTALL_DIR"
else
mkdir -p $INSTALL_DIR
[[ -d $INSTALL_DIR ]] || die "Cannot create $INSTALL_DIR"
fi
ABS_INSTALL_DIR=$(cd $INSTALL_DIR &>/dev/null; pwd)
echo "Installing perl $LATEST_VERSION to $INSTALL_DIR, this may take a while..."
$HTTP_GET $HTTP_GET_OPTION $LATEST_URL | $TAR_CMD $TAR_OPTION - --strip-components 1 -C $INSTALL_DIR
if [[ ! -f $INSTALL_DIR/bin/perl ]]; then
die "Failed to install perl"
fi
cat <<EOF
Successfully installed perl $LATEST_VERSION.
To use this perl, add the following line to ~/.bash_profile or ~/.zshrc:
export PATH=$ABS_INSTALL_DIR/bin:\$PATH
EOF