Skip to content

Commit

Permalink
comma three support (#58)
Browse files Browse the repository at this point in the history
* support TICI, theoretically

* need sudo for AGNOS

* Clean up installation

* update notes

* fix tici read-only remount

* revert debugging changes

* only remount rw when *needed*

* print improvements

* print improvements

* add exit message

* run with sudo

fix

* info

* info

* exit if not supported

* clean up references to /home/.bashrc

* more emoji!

more emoji!

* update changelog

* clean up

* update date
  • Loading branch information
sshane authored Nov 17, 2021
1 parent cf54090 commit c966108
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 122 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Release 0.1.17 (2021-11-17)
=====

* Support comma three, which has its .bashrc located elsewhere.
* Nicer user-facing installation process
* Clean up installation logic:
* Minimal modification to the system .bashrc file, only one `source` line is appended to the community .bashrc
* Much safer: the previous installer moved the system .bashrc file to a permanently rw partition

Release 0.1.16 (2021-04-18)
=====

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ If you have any questions about the development process, or have any ideas you w
To install these utilities, SSH into your comma device running neos (ie Comma 2, Eon, etc), and paste in the following:
```bash
bash <(curl -fsSL install.emu.sh) # the brain of the bird
source /home/.bashrc
source /data/community/.bashrc
```

<!-- <img src="https://thumbs.gfycat.com/DopeyHairyGeese-size_restricted.gif" alt ="" /> -->
Expand Down
13 changes: 0 additions & 13 deletions commands/fork/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,9 @@
DEFAULT_BRANCH_START = 'HEAD branch: '
REMOTE_BRANCHES_START = 'Remote branches:\n'
REMOTE_BRANCH_START = 'Remote branch:'
CLONING_PATH = '{}/.cloning'.format(OH_MY_COMMA_PATH)
DEFAULT_REPO_NAME = 'openpilot'


def set_cloning(cloning):
if cloning:
if not os.path.exists(CLONING_PATH):
with open(CLONING_PATH, 'w') as f:
pass
else:
if os.path.exists(CLONING_PATH):
os.remove(CLONING_PATH)


def valid_fork_url(url):
import urllib.request
try:
Expand Down Expand Up @@ -419,9 +408,7 @@ def _init(self):
success('Backed up your current openpilot install to {}'.format(bak_dir))

info('Cloning commaai/openpilot into {}, please wait...'.format(OPENPILOT_PATH))
set_cloning(True) # don't git fetch on new sessions
r = run(['git', 'clone', '-b', self.comma_default_branch, GIT_OPENPILOT_URL, OPENPILOT_PATH]) # default to stock/release2 for setup
set_cloning(False)
if not r:
error('Error while cloning, please try again')
return
Expand Down
7 changes: 0 additions & 7 deletions default-bashrcs/.bashrc-community
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/bin/bash
# /data/community/.bashrc: executed by bash(1) for non-login shells after executing /home/.bashrc.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) for examples


## BEGIN .oh-my-comma magic ###

Expand Down Expand Up @@ -38,7 +35,6 @@ HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend


### End of .oh-my-comma magic ###

# This is your space to configure your terminal to your liking
Expand All @@ -48,7 +44,4 @@ shopt -s histappend
cd /data
if [ -d "/data/openpilot" ]; then
cd /data/openpilot
if [ ! -f "/data/community/.oh-my-comma/.cloning" ]; then
git fetch # auto check git refs, but don't update
fi
fi
1 change: 0 additions & 1 deletion default-bashrcs/.bashrc-system

This file was deleted.

5 changes: 2 additions & 3 deletions default-bashrcs/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
These files are copied during installation process. If each bashrc exists on the filesystem and contains the `source`
to whatever entrypoint they each point to, then these files will not be overwritten by update. The files in this directory should only be edited when modifying distribution files.
A source to /data/community/.bashrc is made in the system .bashrc file, depending on the system (AGNOS or NEOS).

To edit your own bashrc:
To edit your own bashrc after installation:
```
cd /data/community/
ls -al
Expand Down
Empty file modified emu.py
100644 → 100755
Empty file.
1 change: 0 additions & 1 deletion emu.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
SYSTEM_BASHRC_PATH=/home/.bashrc
export COMMUNITY_PATH=/data/community
export COMMUNITY_BASHRC_PATH=${COMMUNITY_PATH}/.bashrc
export OH_MY_COMMA_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
Expand Down
172 changes: 81 additions & 91 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,148 +18,138 @@
# 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 /home/.bashrc
# source $SYSTEM_BASHRC_PATH depending on system

SYSTEM_BASHRC_PATH=/home/.bashrc
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.16
OMC_VERSION=0.1.17

install_echo() { # only prints if not updating
if [ "$update" != true ]; then
echo "$1"
# 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 [ $update = false ]; then
[[ "$DEBUG" == 'true' ]] && set -x
fi

if [ ! -d "/data/community" ]; then
mkdir /data/community
chmod 755 /data/community
fi

chmod 755 /data/community

if [ ! -d "$OH_MY_COMMA_PATH" ]; then
echo "Cloning..."
echo "Cloning .oh-my-comma"
git clone -b ${GIT_BRANCH_NAME} ${GIT_REMOTE_URL} ${OH_MY_COMMA_PATH}
fi

install_echo "Remounting /system as rewritable (until NEOS 15)"
mount -o rw,remount /system

if [ ! -x "$(command -v powerline-shell)" ] && [ $update = false ]; then
# 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 ) pip install powerline-shell;;
y|Y ) remount_system rw && pip install powerline-shell && remount_system ro;;
* ) echo "Skipping...";;
esac
fi

install_echo "\nInstalling emu utilities..."
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"
printf "\n# automatically added by .oh-my-comma:\n%s\n" "source ${COMMUNITY_BASHRC_PATH}" | sudo tee -a "$SYSTEM_BASHRC_PATH" > /dev/null || exit 1
remount_system ro
printf "✅ Success!\n\n"
fi

if [ -f "$SYSTEM_BASHRC_PATH" ]; then
install_echo "Your system /home/.bashrc exists..."
if grep -q '/home/.bashrc' -e 'source /data/community/.bashrc'
then
install_echo "Found an entry point point for ${COMMUNITY_BASHRC_PATH} in ${SYSTEM_BASHRC_PATH}, skipping changes to /system"
# 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
echo "Your bashrc file is different than the one on the repo. NEOS 15 will redirect all users to store their bashrc in /data/community"
echo "Moving your current bashrc to /data/community"
mv ${SYSTEM_BASHRC_PATH} ${COMMUNITY_BASHRC_PATH}
echo "Copying .bashrc that sources local bashrc to system partition (wont be needed in neos 15)"
cp ${OH_MY_COMMA_PATH}/default-bashrcs/.bashrc-system ${SYSTEM_BASHRC_PATH}
install_echo "Symlink check passed"
fi
else
echo "Creating a .bashrc in /home/ that sources the community bashrc in /data/community/"
cp ${OH_MY_COMMA_PATH}/default-bashrcs/.bashrc-system ${SYSTEM_BASHRC_PATH}
fi

install_echo "Checking /home/.config symlink..."
if [ "$(readlink -f /home/.config/powerline-shell)" != "$OH_MY_COMMA_PATH/.config/powerline-shell" ]; then
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
else
install_echo "Symlink check passed"
# 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

install_echo "Remounting /system as read-only"
mount -o r,remount /system

#Coping user bashrc, outside of system partition
if [ -f "$COMMUNITY_BASHRC_PATH" ]; then
#bashrc found
if grep -q '/data/community/.bashrc' -e 'source /data/community/.oh-my-comma/emu-utils.sh'
then
# v0.1.0 -> v0.1.1
# Test for and patch Backwards compatibility issues with file rename
if grep -q '/data/community/.bashrc' -e '^### End of \.oh-my-comma magic ###$'
then
echo "There's something wrong with your community .bashrc ?? You should copy the one from ${OH_MY_COMMA_PATH}/default-bashrcs/.bashrc-community) to ${COMMUNITY_BASHRC_PATH}"
else
# Patch the current bashrc with the updated settings, without destroying user modifications
echo "Found old entrypoint filename. Removing that line"
rm .bashrc.lock
chmod 755 ${COMMUNITY_BASHRC_PATH}
mv ${COMMUNITY_BASHRC_PATH} ${COMMUNITY_PATH}/.bashrc.lock
sed -i.bak.$(date +"%Y-%m-%d-%T") -e "/^source \/data\/community\/\.oh-my-comma\/emu-utils\.sh$/d" ${COMMUNITY_BASHRC_PATH}.lock
printf "$(sed '/### End of \.oh-my-comma magic ###/q' ${OH_MY_COMMA_PATH}/default-bashrcs/.bashrc-community)\n$(cat ${COMMUNITY_BASHRC_PATH}.lock)\n" >> ${COMMUNITY_BASHRC_PATH}
rm ${COMMUNITY_BASHRC_PATH}.lock
chmod 755 ${COMMUNITY_BASHRC_PATH}
fi
fi

if grep -q '/data/community/.bashrc' -e 'source /data/community/.oh-my-comma/emu.sh'
then
install_echo "Skipping community .bashrc installation as it already sources .oh-my-comma's entrypoint"
else
echo "Your community bashrc is different than what we've got in this repo... Echoing out our entry point to the bottom of your bashrc in /data/community/.bashrc"
printf "\n%s\n" "$(cat ${OH_MY_COMMA_PATH}/default-bashrcs/.bashrc-community)" >> ${COMMUNITY_BASHRC_PATH}
fi
else
echo "Creating the community .bashrc at ${COMMUNITY_BASHRC_PATH}"
touch ${COMMUNITY_BASHRC_PATH}
chmod 755 ${COMMUNITY_BASHRC_PATH}
printf "%s\n" "$(cat ${OH_MY_COMMA_PATH}/default-bashrcs/.bashrc-community)" >> ${COMMUNITY_BASHRC_PATH}
fi
touch ${COMMUNITY_PATH}/.bash_history
chmod 775 ${COMMUNITY_PATH}/.bash_history
#Post-install
if [ $update = false ]; then
printf " Contents of system bashrc: \n"
cat ${SYSTEM_BASHRC_PATH}
printf " End of %s \n\n Contents of community bashrc: \n" "$SYSTEM_BASHRC_PATH"
cat ${COMMUNITY_BASHRC_PATH}
printf " End of %s \n\n" "$COMMUNITY_BASHRC_PATH"
fi

printf "\033[92m"
printf "\n\033[92m"
if [ $update = true ]; then
printf "Successfully updated emu utilities!\n"
echo "Successfully updated emu utilities!"
else
echo "Sourcing /home/.bashrc to apply the changes made during installation"
source /home/.bashrc
printf "\nSuccessfully installed emu utilities\n\n"
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" "${CURRENT_BRANCH}"
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" != true ]; then
printf "\033[0mYou may need to run the following to initialize emu:\n\033[92msource %s/emu.sh\n" "${OH_MY_COMMA_PATH}"
if [ $update = false ]; then
echo "\033[0mYou may want to exit out of this bash instance to automatically source emu"
fi

printf "\033[0m\n" # reset color
Expand Down
1 change: 0 additions & 1 deletion py_utils/emu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
else:
from py_utils.colors import COLORS

SYSTEM_BASHRC_PATH = '/home/.bashrc'
COMMUNITY_PATH = '/data/community'
COMMUNITY_BASHRC_PATH = '/data/community/.bashrc'
OH_MY_COMMA_PATH = '/data/community/.oh-my-comma'
Expand Down
5 changes: 1 addition & 4 deletions update.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/bin/bash
SYSTEM_BASHRC_PATH=/home/.bashrc
COMMUNITY_PATH=/data/community
COMMUNITY_BASHRC_PATH=/data/community/.bashrc
OH_MY_COMMA_PATH=/data/community/.oh-my-comma
PREV_BRANCH=$(cd ${OH_MY_COMMA_PATH} && git rev-parse --abbrev-ref HEAD)
PREV_VERSION=$(cd ${OH_MY_COMMA_PATH} && git describe --tags | grep -Po "^v(\d+\.)?(\d+\.)?(\*|\d+)")
Expand All @@ -23,7 +20,7 @@ echo "======= TO ======="
if git -C $OH_MY_COMMA_PATH log --stat -1 | grep -q 'default-bashrcs/.bashrc-community'; then
if [ "${PREV_VERSION}" != "${CURRENT_VERSION}" ]; then
printf "\n\33[38;5;190mThe default .bashrc has been updated!\033[0m The update has not been applied to retain your custom changes.\nTo update and reset your .bashrc, run the command:\n"
printf "\033[92mcp -fr /data/community/.oh-my-comma/default-bashrcs/.bashrc-community /data/community/.bashrc\033[0m\n\n"
printf "\033[92mcp -fr ${OH_MY_COMMA_PATH}/default-bashrcs/.bashrc-community /data/community/.bashrc\033[0m\n\n"
printf "This will wipe any custom changes you've made!\n"
fi
fi

0 comments on commit c966108

Please sign in to comment.