-
Notifications
You must be signed in to change notification settings - Fork 14
/
setup.sh
executable file
·86 lines (79 loc) · 2.62 KB
/
setup.sh
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
#!/usr/bin/env bash
set -x
set -e
if [ $BROWSER == "MicrosoftEdge" ]; then
exit 0
fi
if [ $BROWSER == "Electron" ]; then
exit 0
fi
if [ $BROWSER == "NodeWebkit" ]; then
exit 0
fi
if [ $BVER == "android" ]; then
exit 0
fi
if [ -z $BVER ]; then
exit 0
fi
# determine the script path
# ref: http://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself
pushd `dirname $0` > /dev/null
SCRIPTPATH=`pwd -P`
popd > /dev/null
# get the browser version string
case $OSTYPE in
darwin*) PLATFORM="mac";;
linux*) PLATFORM="linux";;
esac
VERSION_REGEX="[0-9]+(\.[0-9]+)*"
if [[ $BVER =~ $VERSION_REGEX ]] ; then
echo "BVER is a version number so going to install a specific version"
if [ $BROWSER == 'firefox' ] ; then
TARGET_URL="http://download.cdn.mozilla.net/pub/firefox/releases/$BVER/linux-x86_64/en-US/firefox-$BVER.tar.bz2"
elif [ $BROWSER == 'chrome' ] ; then
TARGET_URL="http://www.slimjet.com/chrome/lnx/chrome64_$BVER.deb"
else
echo "Installing specific versions only works for Chrome or Firefox"
fi
TARGET_VERSION=$BVER
elif [ $BROWSER == "safari" ] && [ $BVER == "unstable" ]; then
OSVER="${OSVER:-10.14}"
# This is quite dangerous, it is scraping the safari download website for the URL. If the format
# of the website changes then it won't work anymore. We should add safari to
# browsersleuth instead
TARGET_URL=`curl https://developer.apple.com/safari/download/ | sed -nE "s/.*href=\"(.*\.dmg)\">.*macOS $OSVER.*/\1/p"`
TARGET_VERSION=`curl https://developer.apple.com/safari/download/ | sed -nE 's/.*>([0-9]+)<\/p>.*$/\1/p'`
else
SLEUTHBIN=`node -e 'console.log(require.resolve("browser-sleuth/sleuth.sh"))'`
TARGET_BROWSER=`$SLEUTHBIN $BROWSER $BVER $PLATFORM`
TARGET_URL=`echo $TARGET_BROWSER | cut -d'|' -f4`
TARGET_VERSION=`echo $TARGET_BROWSER | cut -d'|' -f2`
fi
TARGET_PATH=$SCRIPTPATH/browsers/$BROWSER/$TARGET_VERSION
# make the local bin directory and include it in the path
BINPATH=./browsers/bin
mkdir -p $BINPATH
# install if required
if [ ! -d $TARGET_PATH ]; then
echo "getting $BROWSER $TARGET_VERSION from $TARGET_URL"
source $SCRIPTPATH/install-$BROWSER.sh "$TARGET_URL" "$TARGET_PATH"
fi
# create the symbolic links
case $BROWSER in
chrome)
ln -sf $TARGET_PATH/chrome $BINPATH/chrome-$BVER
$BINPATH/chrome-$BVER --version
;;
firefox)
ln -sf $TARGET_PATH/firefox $BINPATH/firefox-$BVER
$BINPATH/firefox-$BVER --version
;;
safari)
if [ $BVER == "unstable" ]; then
mdls -name kMDItemVersion /Applications/Safari\ Technology\ Preview.app
else
mdls -name kMDItemVersion /Applications/Safari.app
fi
;;
esac