forked from jmarcher/valet-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
valet
executable file
·76 lines (66 loc) · 2.3 KB
/
valet
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
#!/usr/bin/env bash
SOURCE="${BASH_SOURCE[0]}"
SUDOCMDS="install start stop secure share"
# If the current source is a symbolic link, we need to resolve it to an
# actual directory name. We'll use PHP to do this easier than we can
# do it in pure Bash. So, we'll call into PHP CLI here to resolve.
if [[ -L $SOURCE ]]
then
DIR=$(php -r "echo dirname(realpath('$SOURCE'));")
else
DIR="$( cd "$( dirname "$SOURCE" )" && pwd )"
fi
# If we are in the global Composer "bin" directory, we need to bump our
# current directory up two, so that we will correctly proxy into the
# Valet CLI script which is written in PHP. Will use PHP to do it.
if [ ! -f "$DIR/cli/valet.php" ]
then
DIR=$(php -r "echo realpath('$DIR/../laravel/valet');")
fi
# If the command is one of the commands that requires "sudo" privileges
# then we'll proxy the incoming CLI request using sudo, which allows
# us to never require the end users to manually specify each sudo.
if [[ $SUDOCMDS =~ $1 ]]
then
if [[ "$EUID" -ne 0 ]]
then
sudo $SOURCE "$@"
exit
fi
fi
# If the command is to run the updater we'll run the updater script and
# let it handle this entire update. It will download a fresh copy of
# Valet and replace the current install with the "fresh" download.
if [[ "$1" = "update" ]]
then
bash $DIR/cli/scripts/update.sh
exit
# If the command is the "share" command we will need to resolve out any
# symbolic links for the site. Before starting Ngrok, we will fire a
# process to retrieve the live Ngrok tunnel URL in the background.
elif [[ "$1" = "share" ]]
then
HOST="${PWD##*/}"
DOMAIN=$(php "$DIR/cli/valet.php" domain)
for linkname in ~/.valet/Sites/*; do
if [[ "$(readlink $linkname)" = "$PWD" ]]
then
HOST="${linkname##*/}"
fi
done
if [[ -z "$2" ]]
then
REGION="us"
else
REGION="$2"
fi
# Fetch Ngrok URL In Background...
bash "$DIR/cli/scripts/fetch-share-url.sh" &
sudo -u $USER "$DIR/bin/ngrok" http -host-header=rewrite -region="$REGION" "$HOST.$DOMAIN:80"
exit
# Finally, for every other command we will just proxy into the PHP tool
# and let it handle the request. These are commands which can be run
# without sudo and don't require taking over terminals like Ngrok.
else
php "$DIR/cli/valet.php" "$@"
fi