Skip to content

Commit

Permalink
Prepare scripts for testing on another VM.
Browse files Browse the repository at this point in the history
  • Loading branch information
ariutta committed Dec 8, 2017
1 parent 674d37b commit 95c05e2
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
6 changes: 3 additions & 3 deletions wpi/extensions/GPMLConverter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ Executables will be located here:
> /nix/var/nix/profiles/default/bin/bridgedb
## Permissions
Make sure you're part of the "wikipathways" group.
Make sure you're part of the "wp-devs" group.
```sh
sudo adduser ariutta wikipathways
sudo adduser ariutta wp-devs
```
wikipathways group members should be able to read, write and execute files.
www-data should only be able to read and execute files. It's not secure for it to be able to write the files.
```sh
sudo chown -R www-data:wikipathways /var/www/dev.wikipathways.org/wpi/extensions/GPMLConverter/
sudo chown -R www-data:wp-devs /var/www/dev.wikipathways.org/wpi/extensions/GPMLConverter/
sudo chmod -R g+rwx /var/www/dev.wikipathways.org/wpi/extensions/GPMLConverter/
sudo chmod -R u+rx-w /var/www/dev.wikipathways.org/wpi/extensions/GPMLConverter/
```
Expand Down
62 changes: 62 additions & 0 deletions wpi/extensions/GPMLConverter/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#! /usr/bin/env bash

# run this as: sudo -i $(pwd)/install
# TODO why do we use "su -c" like this for installing nix but not GPMLConverter?: sudo -i su -c $(pwd)/nix-install-deb-multiuser

set -e

# see https://stackoverflow.com/a/246128/5354298
script_dir() { echo "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; }

# see https://stackoverflow.com/a/24067243/5354298
version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; }

# see https://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
is_installed() { hash $1 2>/dev/null || { false; } }
exit_if_not_installed() { is_installed $1 || { echo >&2 "I require $1 but it's not installed. Aborting. See https://nixos.org/nix/manual/#sec-prerequisites-source."; exit 1; } }
function ensure_installed() {
if ! is_installed $1 ; then
echo "Installing missing dependency $1...";
$2;
fi
}

echo "Installing/Updating GPMLConverter"

if [ "$HOME" != '/root' ]; then
cat >&2 <<'END_HEREDOC'
Error: install be run as root.
Please cd to the dir containing this script and run it as:
sudo -i $(pwd)/install
END_HEREDOC
exit;
fi

cd $HOME;

# Checking Dependencies.
exit_if_not_installed nix-channel;
exit_if_not_installed nix-env;

nix-channel --update
nix-env -u '*'

ensure_installed jq "nix-env -i jq";
ensure_installed node "nix-env -i nodejs";
ensure_installed node2nix "nix-env -f <nixpkgs> -iA nodePackages.node2nix";

cd $(script_dir);

rm -f default.nix node-packages.nix node-env.nix;
node2nix --flatten -6 -i node-packages.json
nix-env -f default.nix -i

APACHE_ENV_VARS_PATH="/etc/apache2/envvars";
NIX_BIN_PATH_GLOBAL="/root/.nix-profile/bin";
if ! cat $APACHE_ENV_VARS_PATH | grep $NIX_BIN_PATH_GLOBAL; then
echo '' >> $APACHE_ENV_VARS_PATH;
echo '# Added to allow WikiPathways to access CLI tools installed via nix.' >> $APACHE_ENV_VARS_PATH;
echo "PATH=\$PATH:$NIX_BIN_PATH_GLOBAL" >> $APACHE_ENV_VARS_PATH;
fi

echo "Success! GPMLConverter installed/updated."
10 changes: 9 additions & 1 deletion wpi/extensions/GPMLConverter/nix-install-deb-multi-user
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ check_installed() { hash $1 2>/dev/null || { echo >&2 "I require $1 but it's not

echo "Performing a multi-user installation of Nix..."

if [ $HOME!="/root" ]; then
if [ "$HOME" != '/root' ]; then
cat >&2 <<'END_HEREDOC'
Error: nix-install-deb-multi-user must be run as root.
Please cd to the dir containing this script and run it as:
Expand Down Expand Up @@ -96,8 +96,16 @@ touch /etc/default/nix
systemctl enable nix
systemctl start nix

touch "$HOME/.bashrc";
$(cat >> "/etc/systemd/system/nix.service" <<'END_HEREDOC'
export NIX_REMOTE=daemon
. /usr/local/etc/profile.d/nix.sh
END_HEREDOC
)

SETUP_USER_SCRIPT_PATH="/usr/local/bin/nix-setup-user"
$(cat > "$SETUP_USER_SCRIPT_PATH" <<'END_HEREDOC'
# NOTE: this is only for setting up non-root users.
chmod u+rwx "$SETUP_USER_SCRIPT_PATH"
chmod g+rx-w "$SETUP_USER_SCRIPT_PATH"
chmod o+rx-w "$SETUP_USER_SCRIPT_PATH"
Expand Down

0 comments on commit 95c05e2

Please sign in to comment.