Skip to content

Commit

Permalink
Unix: handle paths with spaces (#12)
Browse files Browse the repository at this point in the history
Improve documentation & messages
  • Loading branch information
mwermelinger committed Aug 4, 2023
1 parent 50cc359 commit 6531b97
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
15 changes: 10 additions & 5 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
Write-Host "Installing software for M269 23J..."

# This script works in one of two modes:
# - If no argument is given, the script must be in the M269 folder and
# - If no argument is given, this script must be in the M269 folder and
# the other installation files are downloaded from GitHub.
# - If an argument is given, it's the M269 folder, and the script and the other
# installation files are in a separate folder.
# - If an argument is given, it's the M269 folder, and this script and the other
# installation files are in the current folder.

# The first mode installs the latest software,
# for the current presentation or for testing the next presentation.
# The second mode is for installing the software for a past presentation,
# by first downloading the past installation files from GitHub.

$SITE = "https://dsa-ou.github.io/m269-installer"
$DOC = "See $SITE for details."
Expand All @@ -30,15 +35,15 @@ function is-m269-folder {
}

if ($args.Length -gt 1) {
Write-Host "Usage: ./install-m269.sh [path to M269 folder]"
Write-Host "Usage: .\install.ps1 [path to M269 folder]"
Write-Host "If no argument is given, this script must be in your M269 folder."
Write-Host "If an argument is given, it must be the path to your M269 folder."
Write-Host $DOC
exit
} elseif ($args.Length -eq 0) {
$FOLDER = pwd
is-m269-folder $FOLDER
Write-Host "Installing M269 files..."
Write-Host "Downloading and installing M269 files..."
$GITHUB = "https://raw.githubusercontent.com/dsa-ou/m269-installer/main/"
foreach ($file in $FILES) {
Invoke-WebRequest -Uri ($GITHUB + $file) -OutFile $file
Expand Down
36 changes: 21 additions & 15 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
echo "Installing software for M269 23J..."

# This script works in one of two modes:
# - If no argument is given, the script must be in the M269 folder and
# - If no argument is given, this script must be in the M269 folder and
# the other installation files are downloaded from GitHub.
# - If an argument is given, it's the M269 folder, and the script and the other
# installation files are in a separate folder.
# - If an argument is given, it's the M269 folder, and this script and the other
# installation files are in the current folder.

# The first mode installs the latest software,
# for the current presentation or for testing the next presentation.
# The second mode is for installing the software for a past presentation,
# by first downloading the past installation files from GitHub.

SITE=https://dsa-ou.github.io/m269-installer
DOC="See $SITE for details."
Expand Down Expand Up @@ -49,12 +54,12 @@ then
exit 1
fi

# check that the given path is the M269 folder
# check that the given path (which may have spaces) is the M269 folder
is_m269_folder () {
if [ ! -d $1 ]
if [[ ! -d $1 ]] # single bracket would split path string on spaces
then
msg="doesn't exist or isn't a folder"
elif [[ $(basename $1) != [Mm]269-23[Jj] ]]
elif [[ $(basename "$1") != [Mm]269-23[Jj] ]]
then
msg="must be named m269-23j or M269-23J"
else
Expand All @@ -66,21 +71,22 @@ is_m269_folder () {

if [ $# -gt 1 ]
then
echo "Usage: ./install-m269.sh [path to M269 folder]"
echo "Usage: ./install.sh [path to M269 folder]"
echo "If no argument is given, this script must be in your M269 folder."
echo "If an argument is given, it must be the path to your M269 folder."
echo $DOC
exit 1
elif [ $# -eq 0 ]
then
FOLDER=$(pwd)
is_m269_folder $FOLDER
echo "Installing M269 files..."
is_m269_folder "$FOLDER"
echo "Downloading and installing M269 files..."
for file in $FILES
do
curl -LO https://github.com/dsa-ou/m269-installer/raw/main/$file
done
mkdir -p ~/.jupyter/custom
# don't overwrite existing CSS file
if [ -f ~/.jupyter/custom/$CSS ]
then
cat $CSS >> ~/.jupyter/custom/$CSS
Expand All @@ -89,7 +95,7 @@ then
mv $CSS ~/.jupyter/custom
fi
else
is_m269_folder $1
is_m269_folder "$1"
FOLDER=$(cd "$1"; pwd)
for file in $FILES
do
Expand All @@ -108,7 +114,7 @@ else
else
cp -a $CSS ~/.jupyter/custom
fi
cp -a $CHECK $FOLDER
cp -a $CHECK "$FOLDER"
fi

echo "Creating Python environment $VENV... (this will take a bit)"
Expand All @@ -118,7 +124,7 @@ echo "Downloading and installing Python packages... (this will take long)"
source $VENV/bin/activate # this script runs under bash
pip install --upgrade pip
pip install -r $REQS
pip install pytype==2023.4.27
pip install pytype==2023.4.27 # install pytype only for Unix
deactivate
# if we're in the M269 folder, remove the no longer needed file
if [ $# -eq 0 ]
Expand All @@ -129,9 +135,9 @@ echo "Software has been installed."

echo "Adding shortcut commands to $shell's startup file..."

M269="cd $FOLDER;source $VENV/bin/activate"
NB="jupyter notebook $FOLDER&"
ALLOWED="python3.10 $FOLDER/allowed.py -c $FOLDER/m269.json"
M269="cd \"$FOLDER\";source $VENV/bin/activate"
NB="jupyter notebook \"$FOLDER\"&"
ALLOWED="python3.10 \"$FOLDER/allowed.py\" -c \"$FOLDER/m269.json\""

if [ $shell = "fish" ]
then
Expand Down

0 comments on commit 6531b97

Please sign in to comment.