From 9ef756838bc621eecefa6f095074d071fd92399f Mon Sep 17 00:00:00 2001 From: John Date: Thu, 5 May 2022 16:12:55 -0500 Subject: [PATCH] Attempt fix setup script on Linux Also update CC BY-SA notice of attribution --- .../package-managers/pacman.dependencies | 3 +- setup-development/linux/upgrade-linux.sh | 50 ++++++++++++++----- setup-development/windows/install-windows.ps1 | 2 +- setup-development/windows/upgrade-windows.ps1 | 2 +- .../windows/winget/dependencies.json | 3 -- src/pylex/token.ts | 2 +- 6 files changed, 42 insertions(+), 20 deletions(-) diff --git a/setup-development/linux/package-managers/pacman.dependencies b/setup-development/linux/package-managers/pacman.dependencies index 89859bb..1b50f89 100644 --- a/setup-development/linux/package-managers/pacman.dependencies +++ b/setup-development/linux/package-managers/pacman.dependencies @@ -1,5 +1,4 @@ base-devel -code git -nvm +wget python3 diff --git a/setup-development/linux/upgrade-linux.sh b/setup-development/linux/upgrade-linux.sh index 3e1084d..25ef70a 100644 --- a/setup-development/linux/upgrade-linux.sh +++ b/setup-development/linux/upgrade-linux.sh @@ -3,7 +3,6 @@ #* linux-update.sh: Install and update dependencies of Mind_Reader, on linux. #* Heads-up, this expects to be run from Mind_Reader/setup-development/linux. - # If run with bash -vx, print useful information instead of just a + sign export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' # If run as root, it could be because sudo isn't installed (some people disagree with sudo, especially on Arch) @@ -26,6 +25,31 @@ function dryrun { fi } +# Get whether the user is running in Windows Subsystem for Linux +function getwsl { + grep "[Mm]icrosoft" /proc/version > /dev/null + return $? +} + +# Get the user's default login shell +function getsh { + #* This code was created by user [Todd A. Jacobs](https://stackoverflow.com/users/1301972/todd-a-jacobs) on [StackOverflow](https://stackoverflow.com/a/11059152) and is used in accordance with Creative Commons CC BY-SA 3.0 + getent passwd $LOGNAME | cut -d: -f7 +} + +# Install NVM (this is gross, but the recommended way to install nvm) +function installnvm { + # nvm's install script tries to be smart, so we have to work around its supposed cleverness + usershell=`getsh` + wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | dryrun "$usershell" + # Reload profile + case $usershell in + */bash) dryrun . ~/.bashrc ~/.bashprofile;; + */zsh) dryrun . ~/.zshrc;; + *) "Your shell, $usershell, is currently unsupported by nvm. It's up to you to set up your development environment."; exit;; + esac +} + # Set these variables if you need to install for a different architecture # Valid architectures are "x64", "arm64", "armhf" arch="" @@ -39,29 +63,31 @@ esac if which pacman; then # Install dependencies with pacman + printf "Installing dependencies with pacman...\n" cat ./package-managers/pacman.dependencies | dryrun $ELEVATE pacman -S - + # If not in Windows Subsystem for Linux, install vscode + [[ !(getwsl) ]] && dryrun $ELEVATE pacman -S code + # Install Node Version Manager + installnvm elif which apt-get; then # Install dependencies using apt-get + printf "Installing dependencies with apt...\n" dryrun xargs -a ./package-managers/apt.dependencies $ELEVATE apt-get install -y - - # Install Node Version Manager (nvm) - # TODO: Find a better way to install nvm on Ubuntu, the official NodeJS for <20.04 is so out of date it's unsupported. - curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | dryrun bash - dryrun export NVM_DIR="$HOME/.nvm" - dryrun [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm - dryrun [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion - # Check if vscode exists, if not, install it. # Microsoft doesn't put it in any Ubuntu repos, you have to get it straight from them. # This does have the side effect, however, of installing the official repository - if !(which code); then + # Don't attempt to install vscode if running in WSL; it can cause problems. + if !(which code) && !(getwsl); then #* Install VSCode vscodepackagename="code_amd64.deb" dryrun wget "https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-$arch" -O ./code.deb dryrun $ELEVATE apt install ./code.deb dryrun rm ./code.deb fi + # Install Node Version Manager (nvm) + installnvm + fi cdir=$(pwd) @@ -76,7 +102,7 @@ electronversion="" #* By the time you're working on this project, things are likely going to differ! case `code --version` in #* Each version of VSCode has a corresponding Electron version and Node version - #* These are used when + #* These are used when configuring nvm 1.66.*) electronversion="17.2.0"; nodeversion="16.14.2";; *) nodeversion="--lts";; esac @@ -95,7 +121,7 @@ dryrun npm install dryrun npm audit fix # Use electron-rebuild to rebuild electron -if [ "$electronversion" != "" ]; then +if [[ "$electronversion" != "" ]]; then dryrun electron-rebuild --version $electronversion else printf "%s\n%s\n%s\n%s\n" \ diff --git a/setup-development/windows/install-windows.ps1 b/setup-development/windows/install-windows.ps1 index 86c2d36..3b48a01 100644 --- a/setup-development/windows/install-windows.ps1 +++ b/setup-development/windows/install-windows.ps1 @@ -93,7 +93,7 @@ function Invoke-DryRun { # Reset-Path: Reload the Path environment variable function Reset-Path { Write-Output "Reloading Path..." - #* Courtesy of user [mpen](https://stackoverflow.com/users/65387/mpen) on [StackOverflow](https://stackoverflow.com/a/31845512) + #* This code was created by user [mpen](https://stackoverflow.com/users/65387/mpen) on [StackOverflow](https://stackoverflow.com/a/31845512) and is used in accordance with Creative Commons CC BY-SA 3.0 $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") } diff --git a/setup-development/windows/upgrade-windows.ps1 b/setup-development/windows/upgrade-windows.ps1 index 09094bb..9778fe7 100644 --- a/setup-development/windows/upgrade-windows.ps1 +++ b/setup-development/windows/upgrade-windows.ps1 @@ -83,7 +83,7 @@ function Invoke-Dryrun { # Reset-Path: Reload the Path environment variable function Reset-Path { Write-Output "Reloading Path..." - #* Courtesy of user [mpen](https://stackoverflow.com/users/65387/mpen) on [StackOverflow](https://stackoverflow.com/a/31845512) + #* This code was created by user [mpen](https://stackoverflow.com/users/65387/mpen) on [StackOverflow](https://stackoverflow.com/a/31845512) and is used in accordance with Creative Commons CC BY-SA 3.0 $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") } diff --git a/setup-development/windows/winget/dependencies.json b/setup-development/windows/winget/dependencies.json index ab7f2f6..a20180d 100644 --- a/setup-development/windows/winget/dependencies.json +++ b/setup-development/windows/winget/dependencies.json @@ -15,9 +15,6 @@ }, { "PackageIdentifier": "Microsoft.VisualStudioCode" - }, - { - "PackageIdentifier": "NVAccess.NVDA" } ], "SourceDetails": { diff --git a/src/pylex/token.ts b/src/pylex/token.ts index 9d9a457..dcd7e18 100644 --- a/src/pylex/token.ts +++ b/src/pylex/token.ts @@ -17,7 +17,7 @@ export enum Symbol { FINALLY = "finally", WITH = "with", STATEMENT = "statement", // Indent token, contains non-empty code lines - COMMENT = "comment", + COMMENT = "Comment", EMPTY = "EMPTY", // empty line, used only to associate with the previous line INVALID = "INVALID", EOF = "EOF"