Skip to content

Commit 0aaab17

Browse files
committed
Initial version of an install script. Currently supports Mac & Linux, including Bash & ZSH shells. Needs testing.
1 parent ffd9705 commit 0aaab17

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

bin/install.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env bash
2+
3+
# Ensure PHP is installed
4+
php -v > /dev/null 2>&1
5+
if [[ $? -ne 0 ]]; then
6+
echo "PHP is not found, installation aborted!"
7+
exit 1
8+
fi
9+
10+
# Check if Composer is already globally available
11+
composer -v > /dev/null 2>&1
12+
13+
# Ensure Composer is installed/updated
14+
if [[ $? -ne 0 ]]; then
15+
echo "*** Installing Composer ***"
16+
17+
EXPECTED_SIGNATURE=$(wget https://composer.github.io/installer.sig -O - -q)
18+
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
19+
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
20+
21+
if [ "$EXPECTED_SIGNATURE" = "$ACTUAL_SIGNATURE" ]
22+
then
23+
php composer-setup.php --quiet --filename=composer
24+
RESULT=$?
25+
if [[ $? -eq 0 ]]; then
26+
sudo mv composer /usr/local/bin/composer
27+
RESULT=$?
28+
fi
29+
rm composer-setup.php
30+
if [[ RESULT -ne 0 ]]; then
31+
exit $RESULT
32+
fi
33+
else
34+
>&2 echo 'ERROR: Invalid composer installer signature'
35+
rm composer-setup.php
36+
exit 1
37+
fi
38+
else
39+
echo "*** Updating Composer ***"
40+
composer selfupdate > /dev/null 2>&1
41+
if [[ $? -ne 0 ]]; then
42+
composer global update "composer/composer"
43+
fi
44+
fi
45+
46+
echo "*** Updating shell profiles ***"
47+
# Add Composer's Global Bin to ~/.profile path
48+
if [[ ! -f "~/.profile" ]]; then
49+
touch ~/.profile
50+
fi
51+
grep -q -F 'export COMPOSER_HOME="~/.composer"' ~/.profile || echo 'export COMPOSER_HOME="~/.composer"' >> ~/.profile
52+
grep -q -F 'export PATH=$PATH:$COMPOSER_HOME/vendor/bin' ~/.profile || echo 'export PATH=$PATH:$COMPOSER_HOME/vendor/bin' >> ~/.profile
53+
54+
# Source the .profile to pick up changes
55+
. ~/.profile
56+
57+
# Test if ZSH is installed
58+
zsh --version > /dev/null 2>&1
59+
if [[ $? -eq 0 ]]; then
60+
# Add Composer's Global Bin to ~/.zprofile path
61+
if [[ ! -f "~/.zprofile" ]]; then
62+
touch ~/.zprofile
63+
fi
64+
grep -q -F 'export COMPOSER_HOME="~/.composer"' ~/.zprofile || echo 'export COMPOSER_HOME="~/.composer"' >> ~/.zprofile
65+
grep -q -F 'export PATH=$PATH:$COMPOSER_HOME/vendor/bin' ~/.zprofile || echo 'export PATH=$PATH:$COMPOSER_HOME/vendor/bin' >> ~/.zprofile
66+
67+
# Source the .zprofile to pick up changes
68+
. ~/.zprofile
69+
fi
70+
71+
# Ensure Dealerdirect PHP QA tools are installed globally
72+
echo "*** Installing Dealerdirect PHP QA Tools ***"
73+
composer global require "dealerdirect/qa-tools:@dev"
74+
75+
echo "*** Updating Dealerdirect PHP QA Tools ***"
76+
composer global update "dealerdirect/qa-tools:@dev"

0 commit comments

Comments
 (0)