Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unix: uninstall script #19

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CHECK="allowed.py m269.json"
FILES="$CSS $REQS $CHECK"
COURSE=m269-23j
VENV=~/venvs/$COURSE
CONFIG_VARS=("VENV" "COURSE")

# find out under which shell this script is running
parent_shell=$(ps -o command $PPID)
Expand Down Expand Up @@ -117,6 +118,8 @@ else
cp -a $CHECK "$FOLDER"
fi

CONFIG_VARS+=("FOLDER")

echo "Creating Python environment $VENV... (this will take a bit)"
python3.10 -m venv --prompt $COURSE $VENV

Expand All @@ -141,25 +144,37 @@ ALLOWED="python3.10 \"$FOLDER/allowed.py\" -c \"$FOLDER/m269.json\""

if [ $shell = "fish" ]
then
FILE=~/.config/fish/config.fish
SHELL_CONFIG_FILE=~/.config/fish/config.fish
else
FILE=~/.${shell}rc
SHELL_CONFIG_FILE=~/.${shell}rc
fi

CONFIG_VARS+=("SHELL_CONFIG_FILE")

if [ $shell = "csh" ] || [ $shell = "tcsh" ]
then
echo "alias $COURSE '$M269.csh'" >> $FILE
echo "alias nb '$NB'" >> $FILE
echo "alias allowed '$ALLOWED'" >> $FILE
# tee writes to the file *and* std out
echo "alias $COURSE '$M269.csh'" >> $SHELL_CONFIG_FILE
echo "alias nb '$NB'" >> $SHELL_CONFIG_FILE
echo "alias allowed '$ALLOWED'" >> $SHELL_CONFIG_FILE
else
if [ $shell = "fish" ]
then
echo "alias $COURSE='$M269.fish'" >> $FILE
echo "alias $COURSE='$M269.fish'" >> $SHELL_CONFIG_FILE
else
echo "alias $COURSE='$M269'" >> $FILE
echo "alias $COURSE='$M269'" >> $SHELL_CONFIG_FILE
fi
echo "alias nb='$NB'" >> $FILE
echo "alias allowed='$ALLOWED'" >> $FILE
echo "alias nb='$NB'" >> $SHELL_CONFIG_FILE
echo "alias allowed='$ALLOWED'" >> $SHELL_CONFIG_FILE
fi

echo "All done. Go to $SITE for further instructions."
M269_CONFIG_FILE=$FOLDER/.m269rc
CONFIG_VARS+=("M269_CONFIG_FILE")

# Write the name=value pairs to m269 config file
for var_name in "${CONFIG_VARS[@]}"; do
var_value="${!var_name}"
echo "$var_name=$var_value" >> "$M269_CONFIG_FILE"
done

echo "All done. Go to $SITE for further instructions."
49 changes: 49 additions & 0 deletions uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# Confirm uninstallation
echo "Warning: After uninstallation, you will need a Jupyter environment to open and run your notebooks."
read -p "Proceed with uninstallation? [y/N] " response
case $response in
[yY])
;;
*)
exit 1
;;
esac

# Assume variables VENV, COURSE, FOLDER, SHELL_CONFIG_FILE,
# will be in the m269 config file
source .m269rc
if [[ $? -ne 0 ]]; then
echo "Failed to source the configuration file "
exit 1
fi

# Remove the virtual environment
echo "Removing the virtual environment..."
rm -rf "$VENV"

# Remove allowed.py and m269.json from current directory
echo "Removing allowed.py and m269.json from $FOLDER... "
rm -f $FOLDER/allowed.py $FOLDER/m269.json

# Remove aliases from the configuration file
echo "Removing shortcut commands from $SHELL_CONFIG_FILE..."

ALIASES=("alias nb" "alias allowed" "alias $COURSE")

cp "$SHELL_CONFIG_FILE" "$SHELL_CONFIG_FILE".backup
for alias in "${ALIASES[@]}"; do
sed -i "/^$alias/d" "$SHELL_CONFIG_FILE"
done

# Remove lines from ~/.jupyter/custom/custom.css

# Special characters need to be escaped for use in regex
START_DELIM="\/\* Start of M269-23J notebook styling. \*\/"
END_DELIM="\/\* End of M269-23J notebook styling. \*\/"
CSS_FILE=~/.jupyter/custom/custom.css

cp "$CSS_FILE" "$CSS_FILE".backup
echo "Removing custom styling from $CSS_FILE ..."
sed -i "/$START_DELIM/,/$END_DELIM/d" "$CSS_FILE"