-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathinstall.sh
executable file
·164 lines (143 loc) · 5.65 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/bash
# _
# -=(')
# ;;
# //
# //
# : '.---.__
# | --_-_)__)
# `.____,'
# \ \ ___ ._ _ _ _ _
# ___\ \ / ._>| ' ' || | |
# ( \ \___.|_|_|_|`___|
# \
# /
# This is the install script for https://emu.sh/
# Located on git at https://github.com/emu-sh/.oh-my-comma
# To install this, ssh into your comma device and paste:
# bash <(curl -fsSL install.emu.sh) # the brain of the bird
# source $SYSTEM_BASHRC_PATH depending on system
if [ ! -f /EON ] && [ ! -f /TICI ]; then
echo "Attempting to install on an unsupported platform"
echo "emu only supports comma.ai devices at this time"
exit 1
fi
SYSTEM_BASHRC_PATH=$([ -f /EON ] && echo "/home/.bashrc" || echo "/etc/bash.bashrc")
COMMUNITY_PATH=/data/community
COMMUNITY_BASHRC_PATH=/data/community/.bashrc
OH_MY_COMMA_PATH=/data/community/.oh-my-comma
GIT_BRANCH_NAME=master
GIT_REMOTE_URL=https://github.com/emu-sh/.oh-my-comma.git
OMC_VERSION=0.1.17
install_echo() { # only prints if not updating
if [ "$update" != true ]; then
# shellcheck disable=SC2059
printf -- "$1\n"
fi
}
install_community_bashrc() {
# Copies default-bashrcs/.bashrc-community to /data/community/.bashrc
cp "${OH_MY_COMMA_PATH}/default-bashrcs/.bashrc-community" $COMMUNITY_BASHRC_PATH
chmod 755 ${COMMUNITY_BASHRC_PATH}
echo "✅ Copied ${OH_MY_COMMA_PATH}/default-bashrcs/.bashrc-community to ${COMMUNITY_BASHRC_PATH}"
}
remount_system() {
# Mounts the correct partition at which each OS's .bashrc is located
writable_str=$([ "$1" = "rw" ] && echo "writable" || echo "read-only")
if [ -f /EON ]; then
permission=$([ "$1" = "ro" ] && echo "r" || echo "rw") # just maps ro to r on EON
install_echo "ℹ️ Remounting /system partition as ${writable_str}"
mount -o "$permission",remount /system || exit 1
else
install_echo "ℹ️ Remounting / partition as ${writable_str}"
sudo mount -o "$1",remount / || exit 1
fi
}
# System .bashrc should exist
if [ ! -f "$SYSTEM_BASHRC_PATH" ]; then
echo "Your .bashrc file does not exist at ${SYSTEM_BASHRC_PATH}"
exit 1
fi
update=false
if [ $# -ge 1 ] && [ $1 = "update" ]; then
update=true
fi
if [ ! -d "/data/community" ]; then
mkdir /data/community
chmod 755 /data/community
fi
if [ ! -d "$OH_MY_COMMA_PATH" ]; then
echo "Cloning .oh-my-comma"
git clone -b ${GIT_BRANCH_NAME} ${GIT_REMOTE_URL} ${OH_MY_COMMA_PATH}
fi
# FIXME: figure out how to install pip packages in AGNOS
if [ -f /EON ] && [ ! -x "$(command -v powerline-shell)" ] && [ $update = false ]; then
echo "Do you want to install powerline? [You will also need to install the fonts on your local terminal.]"
read -p "[Y/n] > " choices
case ${choices} in
y|Y ) remount_system rw && pip install powerline-shell && remount_system ro;;
* ) echo "Skipping...";;
esac
fi
install_echo "ℹ️ Installing emu utilities\n"
# If community .bashrc is already sourced, do nothing, else merely append source line to system .bashrc
if grep -q "$SYSTEM_BASHRC_PATH" -e "source ${COMMUNITY_BASHRC_PATH}"; then
install_echo "✅ Community .bashrc is sourced in system .bashrc, skipping"
else
# Append community .bashrc source onto system .bashrc
remount_system rw
echo "ℹ️ Sourcing community .bashrc in system .bashrc"
msg="\n# automatically added by .oh-my-comma:\nif [ -f ${COMMUNITY_BASHRC_PATH} ]; then\n source ${COMMUNITY_BASHRC_PATH}\nfi\n"
if [ -f /TICI ]; then # need to sudo on AGNOS
printf "$msg" | sudo tee -a "$SYSTEM_BASHRC_PATH" > /dev/null || exit 1
else
printf "$msg" | tee -a "$SYSTEM_BASHRC_PATH" > /dev/null || exit 1
fi
remount_system ro
printf "✅ Success!\n\n"
fi
# FIXME: not applicable on TICI
if [ -f /EON ]; then
install_echo "Checking /home/.config symlink..."
if [ "$(readlink -f /home/.config/powerline-shell)" != "$OH_MY_COMMA_PATH/.config/powerline-shell" ]; then
remount_system rw # FIXME: do we need /system rw to access /home on NEOS?
echo "Creating a symlink of ${OH_MY_COMMA_PATH}/.config/powerline-shell to /home/.config/powerline-shell"
ln -s ${OH_MY_COMMA_PATH}/.config/powerline-shell /home/.config/powerline-shell
remount_system ro
else
install_echo "Symlink check passed"
fi
fi
# If community .bashrc file doesn't exist, copy from .bashrc-community
if [ ! -f "$COMMUNITY_BASHRC_PATH" ]; then
echo "ℹ️ Creating your community .bashrc at ${COMMUNITY_BASHRC_PATH}"
install_community_bashrc
elif [ $update = false ]; then
printf "\n❗ A .bashrc file already exists at ${COMMUNITY_BASHRC_PATH}, but you're installing .oh-my.comma\n"
printf "Would you like to overwrite it with the default to make sure it's up to date?\n\n"
read -p "[Y/n]: " overwrite
case ${overwrite} in
n|N ) printf "Skipping...\n";;
* ) install_community_bashrc;;
esac
fi
touch ${COMMUNITY_PATH}/.bash_history
chmod 775 ${COMMUNITY_PATH}/.bash_history
printf "\n\033[92m"
if [ $update = true ]; then
echo "✅ Successfully updated emu utilities!"
else
echo "✅ Successfully installed emu utilities!"
fi
CURRENT_BRANCH=$(cd ${OH_MY_COMMA_PATH} && git rev-parse --abbrev-ref HEAD)
if [ "${CURRENT_BRANCH}" != "master" ]; then
printf "\n❗ \033[0;31mWarning:\033[0m your current .oh-my-comma git branch is %s. If this is unintentional, run:\n\033[92mgit -C /data/community/.oh-my-comma checkout master\033[0m\n\n" "${CURRENT_BRANCH}"
fi
install_echo "Current version: $OMC_VERSION" # prints in update.sh
if [ $update = false ]; then
printf "\033[0mYou may want to exit out of this bash instance to automatically source emu\n"
fi
printf "\033[0m\n" # reset color
if [ $update = false ]; then
set +x
fi