Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
Making installation script more robust:
Browse files Browse the repository at this point in the history
- Updated script SHEBANG to point to env instead of directly to bash. This allows end systems to start with the appropriate bash installation (in case a different version is installed to a different location)
- Script creates virtual environment for python3, this mitigates the need to manually check for python3 and safely isolates the installation of packages from the system's packages
- Changed the way the installer detects package managers. Prior way checked for a the presence of a folder and assumed the os, which then assumed the installation command. If we check for the installation command directly, we make fewer asumptions and have the flexibility to check for different package managers in a miriade of ways (some OSes can have different package managers. EG: osx can have homebrew or macports.)
- Added shebangs to python scripts, they can utilize the appropriate python. When the venv python is activate, env will use it.
  • Loading branch information
niko-dunixi committed Dec 12, 2019
1 parent 157558b commit bc02183
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ AI-Adventure-2bb65e3a4e2f.json
*.py[cod]
data/text_adventures.txt
venv/
.vscode/
generator
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ To play the game locally, it is recommended that you have an nVidia GPU with 12
```
git clone https://github.com/AIDungeon/AIDungeon/
cd AIDungeon
./install.sh
./install.sh # Installs system packages and creates python3 virtual environment
./download_model.sh
python3 play.py
source ./venv/bin/activate
./play.py
```

Community
Expand Down
78 changes: 32 additions & 46 deletions install.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,60 +1,46 @@
#!/bin/bash
#!/usr/bin/env bash
set -e
cd "$(dirname "${0}")"
BASE_DIR="$(pwd)"

declare -A OS_INFO;
OS_INFO[/etc/debian_version]="apt-get install"
OS_INFO[/etc/alpine-release]="apk --update add"
OS_INFO[/etc/centos-release]="yum install"
OS_INFO[/etc/fedora-release]="dnf install"
OS_INFO[/etc/arch-release]="pacman -S"
PYTHON_VER=$(python --version | sed -En "s/Python //p" | cut -c1-3)
PACKAGES=(aria2 git unzip wget)

pip_install () {
if [ "$PYTHON_VER" != "3.6" ]; then
echo "One of the packages 'Tensorflow 1.15' only supports Python 3.6.x"
echo "Your default Python installation is $PYTHON_VER.x."
echo "You'll need to install Python 3.6 manually and then do"
echo "pip install -r ./requirements.txt"
echo "If you have 3.6 installed, please enter the full path of pip3.6."
echo "Leave blank to exit the installation."
read PIP36
else
PIP36=$(which pip)

fi
if [[ ! -z "$PIP36" ]]; then
echo "Installing Python packages."
sudo ${PIP36} install --upgrade pip setuptools
sudo ${PIP36} install -r $BASE_DIR/requirements.txt
if [ ! -d "./venv" ]; then
python3 -m venv ./venv
fi
echo "Once everything is installed, play the game with 'python3.6 ./play.py'"
exit
source "${BASE_DIR}/venv/bin/activate"
pip install --upgrade pip setuptools
pip install -r "${BASE_DIR}/requirements.txt"
}

aid_install () {
echo "Determining package manager."
for f in ${!OS_INFO[@]}
do
if [[ -f $f ]]; then
echo "Found $f."
PACKAGE_MANAGER=${OS_INFO[$f]}
fi
done
if [ -z "$PACKAGE_MANAGER" ]; then
is_command() {
command -v "${@}" > /dev/null
}

system_package_install() {
PACKAGES=(aria2 git unzip wget)
if is_command 'apt-get'; then
sudo apt-get install ${PACKAGES[@]}
elif is_command 'brew'; then
brew install ${PACKAGES[@]}
elif is_command 'yum'; then
sudo yum install ${PACKAGES[@]}
elif is_command 'dnf'; then
sudo dnf install ${PACKAGES[@]}
elif is_command 'packman'; then
sudo packman -S ${PACKAGES[@]}
elif is_command 'apk'; then
sudo apk --update add ${PACKAGES[@]}
else
echo "You do not seem to be using a supported package manager."
echo "Please make sure ${PACKAGES[@]} are installed then press [ENTER]"
read NOT_USED
else
sudo ${PACKAGE_MANAGER} ${PACKAGES[@]}
fi
pip_install
else
echo "aria2c isn't available in PATH."
echo "Exiting."
exit
fi
}

aid_install
install_aid () {
pip_install
system_package_install
}

install_aid
1 change: 1 addition & 0 deletions play.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
import os
import sys
import time
Expand Down
1 change: 1 addition & 0 deletions play_dm.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
import os
import sys
import time
Expand Down

0 comments on commit bc02183

Please sign in to comment.