Skip to content

Commit

Permalink
Add uninstall.sh to FILES; Change url to this branch for testing (mus…
Browse files Browse the repository at this point in the history
…t change back before merge)
  • Loading branch information
densnow committed Aug 24, 2023
1 parent 5e52056 commit 7650035
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
5 changes: 3 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SITE=https://dsa-ou.github.io/m269-installer
DOC="See $SITE for details."
CSS=custom.css
REQS=requirements.txt
CHECK="allowed.py m269.json"
CHECK="allowed.py m269.json uninstall.sh"
FILES="$CSS $REQS $CHECK"
COURSE=m269-23j
VENV=~/venvs/$COURSE
Expand Down Expand Up @@ -87,7 +87,8 @@ then
echo "Downloading and installing M269 files..."
for file in $FILES
do
curl -LO https://github.com/dsa-ou/m269-installer/raw/main/$file
# WARNING: CHANGE URL BACK TO MAIN BRANCH BEFORE MERGING!!!
curl -LO https://github.com/dsa-ou/m269-installer/raw/14-create-uninstallation-scripts/$file
done
mkdir -p ~/.jupyter/custom
# don't overwrite existing CSS file
Expand Down
13 changes: 7 additions & 6 deletions uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
# - Optionally clears M269 styling from Jupyter's custom.css.

# Note: this script expects FOLDER and SHELL_CONFIG_FILE to be set during the
# installation process (inserted with sed in install.sh).
# installation process (inserted with sed via install.sh).

COURSE=m269-23j
VENV=~/venvs/$COURSE
CSS_FILE=~/.jupyter/custom/custom.css
COURSE_YEAR=23
SITE=https://dsa-ou.github.io/m269-installer

# Check FOLDER and SHELL_CONFIG_FILE have been set
# Check FOLDER and SHELL_CONFIG_FILE have been set i.e inserted via install.sh
if [[ -z "$FOLDER" ]] || [[ -z "$SHELL_CONFIG_FILE" ]]; then
echo "Error: critical variables have not been set"
exit 1
Expand All @@ -43,12 +43,13 @@ confirm() {
echo "Warning: This script will make the following changes: "
echo " - Remove the virtual environment in $VENV."
echo " - Remove the aliases 'nb', 'allowed' and '$COURSE' from $SHELL_CONFIG_FILE"
echo " - Optionally removes M269 custom styling from $CSS_FILE"
echo "As a result, Jupyter notebooks will no longer be readable or executable unless another Jupyter environment exists."
if ! confirm "Proceed with uninstallation?"; then
exit 0
fi

# Verify and remove the virtual environment folder.
# Verify and remove the virtual environment.
remove_venv() {
test -n "$VENV" || return 1
test -d "$VENV" || return 1
Expand All @@ -63,7 +64,7 @@ remove_venv || { echo "Error: failed to remove the virtual environment."; exit 1
# Remove allowed.py and m269.json from M269 folder
for file in "allowed.py" "m269.json"; do
target="$FOLDER/$file"
if [ -f "$target" ]; then
if [[ -f "$target" ]]; then
echo "Removing $file from $FOLDER..."
rm "$target"
else
Expand All @@ -73,7 +74,7 @@ done

# Remove aliases from the configuration file
ALIASES=("alias nb" "alias allowed" "alias $COURSE")
if [ -f $SHELL_CONFIG_FILE ]; then
if [[ -f "$SHELL_CONFIG_FILE" ]]; then
echo "Removing shortcut commands from $SHELL_CONFIG_FILE..."
cp "$SHELL_CONFIG_FILE" "$SHELL_CONFIG_FILE".backup
for alias in "${ALIASES[@]}"; do
Expand All @@ -89,7 +90,7 @@ if confirm "Remove M269 custom styling from $CSS_FILE ?"; then
# Special characters need to be escaped for use in regex
START_DELIM="\/\* Start of [Mm]269-$COURSE_YEAR[Jj] notebook styling. \*\/"
END_DELIM="\/\* End of [Mm]269-$COURSE_YEAR[Jj] notebook styling. \*\/"
if [ -f $CSS_FILE ]; then
if [[ -f "$CSS_FILE" ]]; then
cp "$CSS_FILE" "$CSS_FILE".backup
echo "Removing M269 custom styling from $CSS_FILE..."
sed -i "/$START_DELIM/,/$END_DELIM/d" "$CSS_FILE"
Expand Down

0 comments on commit 7650035

Please sign in to comment.