forked from getpopper/popper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
92 lines (82 loc) · 2.77 KB
/
install.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
87
88
89
90
91
92
#!/usr/bin/env sh
# Move the "popper" executable to /usr/local/bin/.
install_system_wide() {
if command -v sudo >/dev/null 2>&1; then
echo "You might be asked for your (sudo) password."
if [ -d "/usr/local/bin" ]; then
sudo -p "password: " -- mv ./popper /usr/local/bin/
else
sudo -p "password: " -- mkdir -p /usr/local/bin/
sudo mv ./popper /usr/local/bin/
fi
else
echo
echo "sudo command not found. Trying to move file without sudo..."
if ! mkdir -p /usr/local/bin/ || ! mv ./popper /usr/local/bin/; then
echo >&2
echo >&2 "Moving popper to /usr/local/bin failed."
echo >&2 "Try executing this script as root user."
exit 1
fi
fi
echo
echo "Popper is now available for all users in this system!"
echo "You can discuss Popper in our slack using the following link:"
echo "https://bit.ly/join-popper-slack"
echo "Also, please give us your feedback via this two-minute survey! https://bit.ly/popper-survey"
echo "Finally, if you encounter issues or have suggestions for features,"
echo "consider contributing to Popper at https://github.com/getpopper/popper."
echo "If you enjoy using Popper, feel free to leave us a star while you're there!"
}
POPPER_VERSION="v2020.09.1"
OS_NAME="$(uname)"
if [ "$OS_NAME" != "Linux" ] && [ "$OS_NAME" != "Darwin" ]; then
echo "Popper only runs on Linux or MacOS. For Windows, we recommend WSL2."
exit 1
fi
command -v docker >/dev/null 2>&1 || { echo >&2 "docker command not found. Aborting."; exit 1; }
# We override the environment variables PATH of the host system with the
# default of Popper’s Docker image. This prevents unforeseeable side effects if
# the host’s PATH is non-standard.
cat > ./popper << "EOF"
#!/usr/bin/env sh
printenv > /tmp/.envfile
docker run --rm -ti \
--volume /tmp:/tmp \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume "$PWD":"$PWD" \
--workdir "$PWD" \
--env-file /tmp/.envfile \
--env "PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
getpopper/popper:v2020.09.1 "$@"
EOF
if [ "$?" -eq 0 ]; then
echo
echo "Installed version $POPPER_VERSION to executable file '$PWD/popper'"
echo
else
echo >&2
echo >&2 "Creating 'popper' file failed."
echo >&2 "Please make sure you have write permission in this folder and try again."
exit 1
fi
chmod +x "./popper"
while true; do
read -p "Do you wish to move this binary to /usr/local/bin/? [Y/n] " yn < /dev/tty
case $yn in
[Yy]* )
install_system_wide
break
;;
[Nn]* ) echo
echo "To make the popper command globally available, add it"
echo "to a folder reachable by the PATH variable."
echo
break
;;
* ) echo
echo "Please answer 'Y' or 'n'."
echo
;;
esac
done