diff --git a/install.sh b/install.sh index e0c8eae..2360295 100755 --- a/install.sh +++ b/install.sh @@ -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 @@ -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 diff --git a/uninstall.sh b/uninstall.sh index 863f90c..048cbb1 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -9,7 +9,7 @@ # - 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 @@ -17,7 +17,7 @@ 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 @@ -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 @@ -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 @@ -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 @@ -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"