Skip to content

Commit

Permalink
Merge pull request #221 from WhitewaterFoundry/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
crramirez authored Jan 28, 2020
2 parents e911c5d + 09f0bb1 commit a41681d
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 165 deletions.
86 changes: 43 additions & 43 deletions pengwin-setup.d/common.sh
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
#!/bin/bash

function process_arguments() {
while [[ $# -gt 0 ]]
do
while [[ $# -gt 0 ]]; do
case "$1" in
--debug|-d|--verbose|-v)
echo "Running in debug/verbose mode"
set -x
shift
--debug | -d | --verbose | -v)
echo "Running in debug/verbose mode"
set -x
shift
;;
-y|--yes|--assume-yes)
echo "Skipping confirmations"
SkipConfirmations=1
shift
-y | --yes | --assume-yes)
echo "Skipping confirmations"
SkipConfirmations=1
shift
;;
--noupdate)
echo "Skipping updates"
SKIP_UPDATES=1
shift
--noupdate)
echo "Skipping updates"
SKIP_UPDATES=1
shift
;;
--norebuildicons)
echo "Skipping rebuild start menu"
SKIP_STARTMENU=1
shift
--norebuildicons)
echo "Skipping rebuild start menu"
SKIP_STARTMENU=1
shift
;;
*)
shift
;;
*)
shift
esac
done
}

function createtmp {
echo "Saving current directory as \$CURDIR"
CURDIR=$(pwd)
TMPDIR=$(mktemp -d)
echo "Going to \$TMPDIR: $TMPDIR"
cd $TMPDIR
function createtmp() {
echo "Saving current directory as \$CURDIR"
CURDIR=$(pwd)
TMPDIR=$(mktemp -d)
echo "Going to \$TMPDIR: $TMPDIR"
cd $TMPDIR
}

function cleantmp {
echo "Returning to $CURDIR"
cd "$CURDIR"
echo "Cleaning up $TMPDIR"
sudo rm -r $TMPDIR # need to add sudo here because git clones leave behind write-protected files
function cleantmp() {
echo "Returning to $CURDIR"
cd "$CURDIR"
echo "Cleaning up $TMPDIR"
sudo rm -r $TMPDIR # need to add sudo here because git clones leave behind write-protected files
}

function updateupgrade {
echo "Applying available package upgrades from repositories."
sudo apt-get upgrade -y
echo "Removing unnecessary packages."
sudo apt-get autoremove -y
function updateupgrade() {
echo "Applying available package upgrades from repositories."
sudo apt-get upgrade -y
echo "Removing unnecessary packages."
sudo apt-get autoremove -y
}

function command_check() {
# Usage: command_check <EXPECTED PATH> <ARGS (if any)>
local execname=$(echo "$1" | sed -e "s|^.*\/||g")
if ("$execname" "$2") > /dev/null 2>&1 ; then
if ("$execname" "$2") >/dev/null 2>&1; then
echo "Executable $execname in PATH"
return 0
elif ("$1" "$2") > /dev/null 2>&1 ; then
elif ("$1" "$2") >/dev/null 2>&1; then
echo "Executable '$execname' at: $1"
return 2
else
Expand Down Expand Up @@ -102,14 +102,14 @@ function menu() {

local exit_status=$?

if [[ ${exit_status} != 0 ]] ; then
if [[ ${exit_status} != 0 ]]; then
echo ${CANCELLED}
return
fi

if [[ -z "${menu_choice}" ]] ; then
if [[ -z "${menu_choice}" ]]; then

if (whiptail --title "None Selected" --yesno "No item selected. Would you like to return to the menu?" 8 60 3>&1 1>&2 2>&3) ; then
if (whiptail --title "None Selected" --yesno "No item selected. Would you like to return to the menu?" 8 60 3>&1 1>&2 2>&3); then
menu "$@"

return
Expand All @@ -125,15 +125,15 @@ function menu() {

function setup_env() {

if ( ! which cmd.exe >/dev/null ); then
if (! which cmd.exe >/dev/null); then
whiptail --title "Wrong user" --msgbox "pengwin-setup was ran with the user \"${USER}\".\n\nRun pengwin-setup from the default user and without sudo" 12 80

exit 0
fi

process_arguments "$@"

if ( ! wslpath 'C:\' > /dev/null 2>&1 ); then
if (! wslpath 'C:\' >/dev/null 2>&1); then
shopt -s expand_aliases
alias wslpath=legacy_wslupath
fi
Expand Down
90 changes: 64 additions & 26 deletions pengwin-setup.d/nodejs.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/bin/bash

source $(dirname "$0")/common.sh "$@"
# shellcheck source=/usr/local/pengwin-setup.d/common.sh
source "$(dirname "$0")/common.sh" "$@"

if [[ ! ${SkipConfirmations} ]]; then
declare SkipConfirmations

if [[ ! "${SkipConfirmations}" ]]; then

if (whiptail --title "NODE" --yesno "Would you like to download and install Node.js (with npm)?" 8 65); then
echo "Installing NODE"
Expand All @@ -19,11 +22,12 @@ menu_choice=$(
"N" "Install with n version manager (fish shell compat. EXPERIMENTAL)" off \
"NVM" "Install with nvm version manager (fish shell compat. EXPERIMENTAL)" off \
"LATEST" "Install latest version via APT package manager" off \
"LTS" "Install LTS version via APT package manager" off \
"LTS" "Install LTS version via APT package manager" off
3>&1 1>&2 2>&3)
3>&1 1>&2 2>&3
)

if [[ ${menu_choice} == "CANCELLED" ]] ; then
if [[ ${menu_choice} == "CANCELLED" ]]; then
echo "Skipping NODE"
exit 1
fi
Expand All @@ -40,7 +44,7 @@ if [[ "$(which npm)" == $(wslpath 'C:\')* ]]; then
exit 1
fi

sudo tee "${NPM_WIN_PROFILE}" << EOF
sudo tee "${NPM_WIN_PROFILE}" <<EOF
# Check if we have Windows Path
if ( which cmd.exe >/dev/null ); then
Expand Down Expand Up @@ -68,21 +72,21 @@ EOF
eval "$(cat "${NPM_WIN_PROFILE}")"
fi

if [[ ${menu_choice} == "N" ]] ; then
if [[ ${menu_choice} == "N" ]]; then
echo "Ensuring we have build-essential installed"
sudo apt-get -y -q install build-essential

echo "Installing n, Node.js version manager"
curl -L https://git.io/n-install -o n-install.sh
env SHELL="$(which bash)" bash n-install.sh -y #Force the installation to bash
env SHELL="$(which bash)" bash n-install.sh -y #Force the installation to bash

N_PATH="$(cat ${HOME}/.bashrc | grep "^.*N_PREFIX.*$" | cut -d'#' -f 1)"
echo "${N_PATH}" | sudo tee "${NPM_PROFILE}"
eval "${N_PATH}"

# Clear N from .bashrc now not needed
filecontents=$(cat "$HOME/.bashrc" | grep -v -e '^.*N_PREFIX.*$')
printf '%s' "$filecontents" > "$HOME/.bashrc"
printf '%s' "$filecontents" >"$HOME/.bashrc"

# Add the path for sudo
SUDO_PATH="$(sudo cat /etc/sudoers | grep "secure_path" | sed "s/\(^.*secure_path=\"\)\(.*\)\(\"\)/\2/")"
Expand All @@ -100,7 +104,7 @@ if [[ ${menu_choice} == "N" ]] ; then
FISH_CONF="$FISH_DIR/n-prefix.fish"

mkdir -p "$FISH_DIR"
sh -c "cat > $FISH_CONF" << EOF
sh -c "cat > $FISH_CONF" <<EOF
#!/bin/fish
set -x N_PREFIX $HOME/n
Expand All @@ -113,7 +117,7 @@ EOF
# Add npm to bash completion
sudo mkdir -p /etc/bash_completion.d
npm completion | sudo tee /etc/bash_completion.d/npm
elif [[ ${menu_choice} == "NVM" ]] ; then
elif [[ ${menu_choice} == "NVM" ]]; then
echo "Installing nvm, Node.js version manager"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

Expand All @@ -126,7 +130,7 @@ elif [[ ${menu_choice} == "NVM" ]] ; then

# Clear nvm from .bashrc now not needed
filecontents=$(cat "$HOME/.bashrc" | grep -v -e '^.*NVM_DIR.*$')
printf '%s' "$filecontents" > "$HOME/.bashrc"
printf '%s' "$filecontents" >"$HOME/.bashrc"

# Add nvm to path, nvm to bash completion
echo "$NVM_PATH" | sudo tee /etc/profile.d/nvm-prefix.sh
Expand All @@ -139,7 +143,7 @@ elif [[ ${menu_choice} == "NVM" ]] ; then
FISH_CONF="$FISH_DIR/nvm-prefix.fish"

mkdir -p "$FISH_DIR"
sh -c "cat > $FISH_CONF" << EOF
sh -c "cat > $FISH_CONF" <<EOF
#!/bin/fish
set -x NVM_DIR $HOME/.nvm
Expand All @@ -162,34 +166,68 @@ EOF
#echo "Defaults secure_path=\"${SUDO_PATH}:${NVM_DIR}/bin\"" | sudo EDITOR='tee ' visudo --quiet --file=/etc/sudoers.d/npm-path

echo "Installing latest Node.js release"
nvm install $(nvm ls-remote | tail -1 | sed -e 's|^\s||g') --latest-npm
nvm install "$(nvm ls-remote | tail -1 | sed -e 's|^\s||g')" --latest-npm

# Add npm to bash completion
npm completion | sudo tee /etc/bash_completion.d/npm
elif [[ ${menu_choice} == "LATEST" ]] ; then
elif [[ ${menu_choice} == "LATEST" ]]; then
echo "Installing latest node.js version from NodeSource repository"

major_vers=12
nodesrc_url="https://deb.nodesource.com/setup_$major_vers.x"
curl -sL "$nodesrc_url" -o repo-install.sh
sudo bash repo-install.sh
major_vers=13
nodesrc_url="https://deb.nodesource.com/setup_${major_vers}.x"
#curl -sL "$nodesrc_url" -o repo-install.sh
#sudo bash repo-install.sh

echo 'Adding the NodeSource signing key to your keyring...'

if [ -x /usr/bin/curl ]; then
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
else
wget -qO- https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
fi

echo "Creating apt sources list file for the NodeSource ${NODENAME} repo..."

echo "deb https://deb.nodesource.com/node_${major_vers}.x buster main" | sudo tee /etc/apt/sources.list.d/nodesource.list
echo "deb-src https://deb.nodesource.com/node_${major_vers}.x buster main" | sudo tee -a /etc/apt/sources.list.d/nodesource.list

echo "Running 'apt-get update' for you..."

sudo apt-get update

version=$(apt-cache madison nodejs | grep 'nodesource' | grep -E "^\snodejs\s|\s$major_vers" | cut -d'|' -f2 | sed 's|\s||g')
sudo apt-get install -y -q nodejs=$version
elif [[ ${menu_choice} == "LTS" ]] ; then
sudo apt-get install -y -q nodejs="${version}"
elif [[ ${menu_choice} == "LTS" ]]; then
echo "Installing LTS node.js version from NodeSource repository"

major_vers=10
major_vers=12
nodesrc_url="https://deb.nodesource.com/setup_$major_vers.x"
curl -sL "$nodesrc_url" -o repo-install.sh
sudo bash repo-install.sh
#curl -sL "$nodesrc_url" -o repo-install.sh
#sudo bash repo-install.sh

echo 'Adding the NodeSource signing key to your keyring...'

if [ -x /usr/bin/curl ]; then
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
else
wget -qO- https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
fi

echo "Creating apt sources list file for the NodeSource ${NODENAME} repo..."

echo "deb https://deb.nodesource.com/node_${major_vers}.x buster main" | sudo tee /etc/apt/sources.list.d/nodesource.list
echo "deb-src https://deb.nodesource.com/node_${major_vers}.x buster main" | sudo tee -a /etc/apt/sources.list.d/nodesource.list

echo "Running 'apt-get update' for you..."

sudo apt-get update

version=$(apt-cache madison nodejs | grep 'nodesource' | grep -E "^\snodejs\s|\s$major_vers" | cut -d'|' -f2 | sed 's|\s||g')
sudo apt-get install -y -q nodejs=$version
sudo apt-get install -y -q nodejs="${version}"
fi
cleantmp

if (whiptail --title "YARN" --yesno "Would you like to download and install the Yarn package manager? (optional)" 8 80) ; then
if (whiptail --title "YARN" --yesno "Would you like to download and install the Yarn package manager? (optional)" 8 80); then
echo "Installing YARN"
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
Expand Down
Loading

0 comments on commit a41681d

Please sign in to comment.