-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall-shellcheck
170 lines (137 loc) · 6.7 KB
/
install-shellcheck
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
#!/bin/bash
# Purpose: To create a working local install of the Shellcheck webui
# Note: This only performs a very basic setup of nginx and php
# Further tweaking, locking down, config etc is on you.
# Author: Rawiri Blundell, 201508
################################################################################
# License information
# This script is released under the MIT license
# Please see: https://github.com/koalaman/shellcheck/issues/423
# Note: Vidar Holen appears to be working towards providing this himself from
# https://github.com/koalaman/shellcheck.net
# You may choose to use that instead. I won't be offended.
################################################################################
# This was created and tested on Debian 8.1, RHEL/CentOS testing is TBD
# Check that we're root
if [[ ! ${EUID} = 0 ]]; then
printf '%s\n' "ERROR: This script must be run as root or with appropriate sudo rights."
exit 1
fi
# Variables
WrkPrcs=$(lscpu | grep "^CPU(s)" | awk '{print $2}')
HostName=$(hostname -f)
################################################################################
#
# ****** Ensure we have the required locale installed - THIS IS CRUCIAL! ******
#
localedef -i en_US -f UTF-8 en_US.UTF-8
#
#
################################################################################
# First we blindly install our dependencies
printf '%s\n' "Installing dependencies, please wait..."
if command -v apt-get &>/dev/null; then
apt-get -y install nginx php5 php5-fpm cabal-install zlib1g-dev
# And now this very naughty way of installing node.js
wget -qO- https://deb.nodesource.com/setup_5.x | bash -
# Shellcheck in the apt repos is old, so we install a more recent version using cabal
# Update cabal's package list
cabal update
# Cursory self-update of the cabal utils
cabal install cabal-install
# Now install shellcheck
cabal install shellcheck
cp ~/.cabal/bin/shellcheck /usr/bin/
elif command -v yum &>/dev/null; then
# This is RHEL/CentOS-6 specific
# Note that the rest of this script is still Debian specific
# See: https://github.com/koalaman/shellcheck/issues/427
yum groupinstall "Development Tools" -y
# May need epel
yum install gmp-devel
ln -s /usr/lib64/libgmp.so.3 /usr/lib64/libgmp.so.10
# And now this very naughty way of installing node.js
wget -qO- https://rpm.nodesource.com/setup_5.x | bash -
# From https://www.haskell.org/platform/linux.html#linux-generic
wget https://haskell.org/platform/download/7.10.2/haskell-platform-7.10.2-a-unknown-linux-deb7.tar.gz
tar xvzf haskell-platform-7.10.2-a-unknown-linux-deb7.tar.gz
./install-haskell-platform.sh
cabal install shellcheck
cp .cabal/bin/shellcheck /usr/local/bin # portable to other el6 systems without haskell
fi
# Setup php. We disable cgi.fix_pathinfo for security reasons
sed -i -e 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php5/fpm/php.ini
# Next we setup nginx, starting with the worker processes setting
# This should match the number of CPU's (cores) available
sed -i -e "s/^worker_processes.*/worker_processes $WrkPrcs;/" /etc/nginx/nginx.conf
# Now we setup the default site
# server_name uses the local FQDN, customise this if you like (e.g. shellcheck.mycompany.tld)
# You may also like to customise the root path. This really should be somewhere in /srv/www/ IMHO
mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak
cat << EOF > /etc/nginx/sites-available/default
server {
listen 80;
server_name ${HostName};
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files \$uri \$uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location ~ .php\$ {
try_files \$uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
}
}
EOF
# Setup directory contents
cd /var/www/html &>/dev/null || exit 1
wget http://shellcheck.net/{favicon.ico,index.html,shellcheck.js,shellcheck.css}
wget https://assets-cdn.github.com/images/modules/logos_page/GitHub-Logo.png
# Uncomment for latest
#wget https://github.com/koalaman/shellcheck.net/raw/master/{shellcheck.css,shellcheck.js,shellcheck.php,shellcheck.sh}
# Comment out for latest
wget https://github.com/koalaman/shellcheck.net/raw/master/{shellcheck.php,shellcheck.sh}
mkdir -p /var/www/html/libace
wget -P /var/www/html/libace/ http://shellcheck.net/libace/{ace.js,mode-sh.js,worker-shellcheck.js}
mkdir -p /var/www/html/jquery/2.2.0/
wget -P /var/www/html/jquery/2.2.0/ https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js
mkdir -p /var/www/html/jqueryui/1.11.4/themes/smoothness/images/
wget -P /var/www/html/jqueryui/1.11.4/ https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js
wget -P /var/www/html/jqueryui/1.11.4/themes/smoothness/ https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css
wget -P /var/www/html/jqueryui/1.11.4/themes/smoothness/images/ https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/images/ui-icons_222222_256x240.png
# Correct where index.html points to its resources
sed -i 's|https://ajax.googleapis.com/ajax/libs/||' index.html
sed -i 's|https://assets-cdn.github.com/images/modules/logos_page/||' index.html
# Correct character encoding issue in shellcheck.js
sed -i 's/.*padding(c.column-1).*/ output += paddy(formatLineNumber("") + padding(c.column-1)) + "^--" + pod(c.level + "c", c.code, c.message) + "\\n";/' shellcheck.js
# Correct character encoding issue in index.html
sed -i 's|.*"GitHub-Logo.png".*| <img src="GitHub-Logo.png" style="height: 1.5ex" alt="GitHub" /> =>|' index.html
# Ensure correct perms
find /var/www/html/ -type f -exec chmod 644 {} \;
chmod +x /var/www/html/shellcheck.sh
# Return from whence we came
cd - &>/dev/null || exit 1
# Restart services, notify user and exit
if command -v systemctl &>/dev/null; then
systemctl restart nginx
systemctl restart php5-fpm
printf '%s\n' "I think I've got it setup now. Please visit http://$(hostname -I) and check for any errors."
exit 0
elif command -v service &>/dev/null; then
service nginx restart
service php5-fpm restart
printf '%s\n' "I think I've got it setup now. Please visit http://$(hostname -I) and check for any errors."
exit 0
else
printf '%s\n' "ERROR: Unable to find 'systemctl' or 'service' in my path." \
"Please restart the nginx and php5-fpm services manually."
exit 1
fi