forked from emojicode/emojicode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·87 lines (73 loc) · 2.02 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
#!/usr/bin/env bash
n=$(tput sgr0)
cyan=$(tput setaf 6)
magenta=$(tput setaf 5)
r=$(tput setaf 1)
binaries=${1:-"/usr/local/bin"}
packages=${2:-"/usr/local/EmojicodePackages"}
self=$0
magicsudod=$3
if [[ "$magicsudod" == "magicsudod" ]]; then
echo "I’ve super user privileges now and will try to perform the installation."
else
echo "👨💻 Hi, I’m the Emojicode Installer!"
echo "I’ll copy the ${cyan}Emojicode Compiler${n} and ${magenta}Real-Time Engine${n} to ${binaries}.${n}"
echo "Then I’ll copy the packages to ${packages}.${n}"
fi
function offerSudo {
if [[ "$magicsudod" == "magicsudod" ]]; then
exit 1
fi
if [ "$EUID" -eq 0 ]; then
exit 1
fi
echo "I can try to rerun myself with sudo."
read -p "If you wish me to do so type y. ➡️ " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo ""
sudo "$self" "$binaries" "$packages" magicsudod
exit $?
fi
exit 1
}
read -p "If you want to proceed type y. ➡️ " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo
if [[ ! -w $binaries ]] ; then
echo "${r}${binaries} is not writeable from this user.${n}"
offerSudo
fi
if [[ ! -w $packages ]] ; then
pp=$(dirname "$packages")
if [[ ! -w $pp ]] ; then
echo "${r}${pp} is not writeable from this user.${n}"
offerSudo
else
if [[ ! -d $packages ]] ; then
echo "Setting up packages directory in ${packages}${n}"
mkdir -p "$packages"
else
echo "${r}${packages} is not writeable from this user.${n}"
offerSudo
fi
fi
fi
(
set -e
echo "Copying builds${n}"
cp emojicode "$binaries/emojicode"
cp emojicodec "$binaries/emojicodec"
chmod 755 "$binaries/emojicode" "$binaries/emojicodec"
echo "Copying packages${n}"
rsync -rl --copy-dirlinks packages/ "$packages"
chmod -R 755 "$packages"
)
if [ $? = 0 ]
then
tput setaf 2
echo "✅ Emojicode was successfully installed.${n}"
else
echo "${r}Installation failed. Please refer to the error above.${n}"
exit 1
fi
fi