Released as 20191022 ('DrivingIT')
[parallel.git] / 10seconds_install
blob452132558b5a59e2914e2b067d95f991f34903a8
1 #!/bin/bash
3 # Copyright (C) 2013-2019 Ole Tange and Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This script downloads the latest version of GNU Parallel, checks
11 # the signature and installs it.
13 # It first tries to install it globally.
14 # If that fails, it does a personal installation.
15 # If that fails, it copies to $HOME/bin
17 # You can download and run the script directly by:
18 # $ (wget -O - pi.dk/3 || lynx -source pi.dk/3 || curl pi.dk/3/ || \
19 # fetch -o - http://pi.dk/3) > install.sh
20 # $ sha1sum install.sh
21 # $ md5sum install.sh
22 # $ sha512sum install.sh
23 # $ bash install.sh
25 run() {
26 # FreeBSD prefers 'fetch', MacOS prefers 'curl', Linux prefers 'wget'
27 get=$(
28 (lynx -source /dev/null && echo lynx -source) ||
29 (fetch -o /dev/null file:///bin/sh && echo fetch -o -) ||
30 (curl -h >/dev/null && echo curl -L) ||
31 (wget -h >/dev/null && echo wget -qO -) ||
32 echo 'No lynx, wget, curl, fetch: Please inform parallel@gnu.org what you use for downloading URLs' >&2
34 if test "$get" = ""; then
35 exit 1
38 if ! perl -e 1; then
39 echo No perl installed. GNU Parallel depends on perl. Install perl and retry.
40 exit 1
43 LANG=C
44 latest=$($get http://ftpmirror.gnu.org/parallel |
45 perl -ne '/.*(parallel-\d{8})/ and print $1."\n"' |
46 perl -e 'print ((reverse sort <>)[0])')
47 if test \! -e $latest.tar.bz2; then
48 # Source tar does not exist
49 rm -f $latest.tar.bz2 $latest.tar.bz2.sig
50 $get http://ftpmirror.gnu.org/parallel/$latest.tar.bz2 > $latest.tar.bz2
51 $get http://ftpmirror.gnu.org/parallel/$latest.tar.bz2.sig > $latest.tar.bz2.sig
54 fetch_keys() {
55 if gpg -h 2>/dev/null >/dev/null ; then
56 # GnuPG installed
57 # Setup .gnupg/gpg.conf if not already done
58 echo | gpg 2>/dev/null >/dev/null
59 keyserver1=keys.gnupg.net
60 keyserver2=pool.sks-keyservers.net
61 if gpg --keyserver $keyserver1 --recv-key 0xFFFFFFF1 ||
62 gpg --keyserver $keyserver2 --recv-key 0xFFFFFFF1 ; then
63 if gpg --keyserver $keyserver1 --recv-key 0x88888888 ||
64 gpg --keyserver $keyserver2 --recv-key 0x88888888; then
65 # OK
66 return 0
67 else
68 echo
69 echo "Cannot fetch keyID 0x88888888, so the signature cannot be checked."
70 return 1
72 else
73 echo
74 echo "Cannot fetch keyID 0xFFFFFFF1, so the signature cannot be checked."
75 return 1
77 else
78 # GnuPG not installed
79 echo
80 echo "GnuPG (gpg) is not installed so the signature cannot be checked."
81 return 1
85 # Check signature - in case ftpmirror.gnu.org is compromised
86 if fetch_keys; then
87 if gpg --with-fingerprint $latest.tar.bz2.sig 2>&1 |
88 perl -e 'exit not grep /^Primary key fingerprint: BE9C B493 81DE 3166 A3BC 66C1 2C62 29E2 FFFF FFF1|^Primary key fingerprint: CDA0 1A42 08C4 F745 0610 7E7B D1AB 4516 8888 8888/, <>'; then
89 # Source code signed by Ole Tange <ole@tange.dk>
90 # KeyID FFFFFFF1/88888888
91 true
92 else
93 # GnuPG signature failed
94 echo
95 echo "The signature on $latest.tar.bz2 is wrong. This may indicate that a criminal has changed the code."
96 echo "THIS IS BAD AND THE CODE WILL NOT BE INSTALLED."
97 echo
98 echo "See http://git.savannah.gnu.org/cgit/parallel.git/tree/README for other installation methods."
99 exit 1
101 else
102 # GnuPG not installed or public keys not downloaded
103 echo "This means that if the code has been changed by criminals, you will not discover that!"
104 echo
105 echo "Continue anyway? (y/n)"
106 read YN </dev/tty
107 if test "$YN" = "n"; then
108 # Stop
109 exit 2
110 else
111 # Continue
112 true
116 bzip2 -dc $latest.tar.bz2 | tar xf -
117 cd $latest || exit 2
118 if ./configure && make && make install; then
119 echo
120 echo GNU $latest installed globally
121 else
122 if ./configure --prefix=$HOME && make && make install; then
123 echo
124 echo GNU $latest installed in $HOME/bin
125 else
126 mkdir -p $HOME/bin/;
127 chmod 755 src/*;
128 cp src/parallel src/env_parallel* src/sem src/sql src/niceload src/parcat $HOME/bin;
129 echo
130 echo GNU $latest copied to $HOME/bin
133 # Is $HOME/bin already in $PATH?
134 if echo $PATH | grep $HOME/bin >/dev/null; then
135 # $HOME/bin is already in $PATH
136 true
137 else
138 # Add $HOME/bin to $PATH for both bash and csh
139 echo 'PATH=$PATH:$HOME/bin' >> $HOME/.bashrc
140 echo 'setenv PATH ${PATH}:${HOME}/bin' >> $HOME/.cshrc
143 # Is $HOME/share/man already in $MANPATH?
144 if echo $MANPATH | grep $HOME/share/man >/dev/null; then
145 # $HOME/share/man is already in $MANPATH
146 true
147 else
148 # Add $HOME/share/man to $MANPATH for both bash and csh
149 echo 'MANPATH=$MANPATH:$HOME/share/man' >> $HOME/.bashrc
150 echo 'setenv MANPATH ${MANPATH}:${HOME}/share/man' >> $HOME/.cshrc
155 # Make sure the whole script is downloaded before starting