2
0
mirror of https://github.com/ComradCollective/Comrad synced 2024-11-13 07:10:49 +00:00
Comrad/script/install

421 lines
7.1 KiB
Plaintext
Raw Normal View History

2020-09-14 15:59:11 +00:00
#!/bin/bash
2020-09-14 13:38:27 +00:00
2020-09-26 13:22:08 +00:00
# funcs (mac doesnt have realpath)
realpath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
2020-09-28 12:59:24 +00:00
echo "$1 $2 $3"
2020-10-04 19:32:58 +00:00
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
MSYS*) machine=MinGw;;
*) machine="UNKNOWN:${unameOut}"
esac
2020-09-26 13:24:53 +00:00
2020-09-26 13:22:08 +00:00
2020-09-14 15:59:11 +00:00
# install pyenv?
2020-09-14 14:40:40 +00:00
2020-09-14 15:59:11 +00:00
echo "
2020-10-02 17:49:17 +00:00
### ## # # ### ## ###
# # # #### # # # # # #
# # # #### ### # # # #
# # # # # # # #### # #
### ## # # # # # # ###
2020-09-14 13:38:27 +00:00
2020-10-02 17:49:17 +00:00
2020-09-14 13:38:27 +00:00
installing...
2020-09-14 16:01:38 +00:00
2020-09-14 15:59:11 +00:00
"
2020-09-14 16:01:38 +00:00
2020-10-04 19:32:58 +00:00
###
# Create paths
######
2020-09-14 16:01:38 +00:00
echo '
2020-10-04 19:32:58 +00:00
1) setting up folders...
2020-09-14 16:01:38 +00:00
2020-09-14 15:59:11 +00:00
'
# install dir?
2020-09-29 13:09:56 +00:00
echo "Where should comrad live on your device?"
path_comrad_default="`realpath ~/comrad`"
2020-09-28 12:42:29 +00:00
2020-09-28 12:59:24 +00:00
if [ "$1" = "-n" ]
2020-09-28 12:42:29 +00:00
then
2020-09-29 13:09:56 +00:00
read -p "[$path_comrad_default] " path_comrad
2020-09-28 12:42:29 +00:00
else
2020-09-29 13:09:56 +00:00
path_comrad=$path_comrad_default
2020-09-28 12:42:29 +00:00
fi
2020-09-29 13:09:56 +00:00
if [ -z "$path_comrad" ]
2020-09-14 15:59:11 +00:00
then
2020-09-29 13:09:56 +00:00
path_comrad=$path_comrad_default
2020-09-14 15:59:11 +00:00
fi
2020-09-22 13:36:20 +00:00
2020-09-29 13:09:56 +00:00
if [ ! -d "$path_comrad" ]
2020-09-14 15:59:11 +00:00
then
2020-09-29 13:09:56 +00:00
mkdir -p $path_comrad
echo "created $path_comrad"
2020-09-14 15:59:11 +00:00
fi
2020-09-29 13:09:56 +00:00
path_lib="$path_comrad/lib"
if [ ! -d "$path_lib" ]
then
mkdir -p $path_lib
echo "created $path_lib"
fi
2020-09-28 13:22:47 +00:00
2020-10-04 19:32:58 +00:00
path_repo="$path_comrad/code"
path_bin="$path_repo/bin"
2020-09-28 13:20:49 +00:00
# if [ ! -d "$path_bin" ]
# then
# mkdir -p $path_bin
# echo "created $path_bin"
# fi
2020-09-27 12:08:32 +00:00
2020-09-14 16:42:03 +00:00
2020-09-14 16:01:38 +00:00
2020-10-04 19:32:58 +00:00
echo '
2) configuring OS environment...
2020-09-14 16:01:38 +00:00
2020-09-14 15:59:11 +00:00
'
2020-10-04 19:32:58 +00:00
echo "Machine $machine detected."
####
# Package manager setups
#
# windows
if [ "$machine" = "MinGw" ]
2020-09-14 15:59:11 +00:00
then
2020-10-04 19:32:58 +00:00
echo "Installing base development packages"
pacman -S curl wget unzip gcc make openssl-devel git
fi
2020-09-28 12:42:29 +00:00
2020-10-04 19:32:58 +00:00
# mac
if [ "$machine" = "Mac" ]
then
if ! command -v brew &> /dev/null
then
echo "Installing homebrew..."
cd "$path_lib"
mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
fi
if ! command -v git &> /dev/null
then
echo "Installing git with brew..."
brew install git
fi
fi
# linux
if [ "$machine" = "Linux" ]
then
if ! command -v git &> /dev/null
then
echo "Installing git with apt..."
sudo apt install git
2020-09-14 15:59:11 +00:00
fi
fi
2020-09-22 13:27:34 +00:00
2020-09-22 12:54:50 +00:00
2020-09-14 16:42:03 +00:00
2020-10-04 19:32:58 +00:00
### Downloading via git!
2020-09-14 16:01:38 +00:00
echo '
2020-10-04 19:32:58 +00:00
2) downloading Comrad...
'
# if exists, pull
if [ -d "$path_repo" ]
then
cd $path_repo
git pull
else
cd $path_comrad
git clone https://github.com/ComradOrg/Comrad.git
mv Comrad code
fi
echo '
4) setting up python miniconda...
2020-09-14 16:01:38 +00:00
2020-09-22 11:13:48 +00:00
# '
2020-09-14 15:59:11 +00:00
2020-09-14 16:42:03 +00:00
2020-10-04 19:32:58 +00:00
#################
## MINICONDA ##
#################
2020-09-14 16:42:03 +00:00
2020-09-22 13:26:18 +00:00
2020-10-04 19:32:58 +00:00
cd $path_comrad
2020-09-29 13:09:56 +00:00
path_conda="$path_comrad/lib/miniconda3"
2020-10-02 18:57:13 +00:00
2020-09-22 13:27:34 +00:00
if [ "$machine" = "Linux" ]
then
2020-09-25 11:50:43 +00:00
if [ ! -f "miniconda.sh" ]
then
2020-10-04 19:32:58 +00:00
echo "downloading miniconda..."
2020-09-25 11:50:43 +00:00
curl https://repo.anaconda.com/miniconda/Miniconda3-py37_4.8.3-Linux-x86_64.sh -o miniconda.sh
chmod +x miniconda.sh
fi
2020-09-25 11:44:39 +00:00
./miniconda.sh -b -f -p "$path_conda"
2020-09-25 11:50:43 +00:00
#rm miniconda.sh
2020-10-04 19:32:58 +00:00
export PATH="$path_conda/bin:$PATH"
2020-09-22 13:36:20 +00:00
fi
2020-10-04 19:32:58 +00:00
# mac
2020-09-22 13:36:20 +00:00
if [ "$machine" = "Mac" ]
2020-09-22 13:27:34 +00:00
then
2020-09-25 11:50:43 +00:00
if [ ! -f "miniconda.sh" ]
then
2020-10-04 19:32:58 +00:00
echo "downloading miniconda..."
2020-09-25 11:50:43 +00:00
curl https://repo.anaconda.com/miniconda/Miniconda3-py37_4.8.3-MacOSX-x86_64.sh -o miniconda.sh
chmod +x miniconda.sh
fi
2020-09-25 11:44:39 +00:00
./miniconda.sh -b -f -p "$path_conda"
2020-10-04 19:32:58 +00:00
export PATH="$path_conda/bin:$PATH"
2020-09-22 13:36:20 +00:00
fi
2020-10-04 19:32:58 +00:00
# windows
2020-10-02 22:14:33 +00:00
if [ "$machine" = "MinGw" ]
2020-09-22 13:27:34 +00:00
then
2020-10-04 08:27:31 +00:00
if [ ! -f "miniconda.exe" ]
2020-10-04 08:30:33 +00:00
then
2020-10-04 19:32:58 +00:00
echo "downloading miniconda..."
2020-10-04 08:27:31 +00:00
arch="$(uname -m)"
if [ "$arch" = "x86_64" ]
then
curl https://repo.anaconda.com/miniconda/Miniconda3-py37_4.8.3-Windows-x86_64.exe -o miniconda.exe
else
curl https://repo.anaconda.com/miniconda/Miniconda3-py37_4.8.3-Windows-x86.exe -o miniconda.exe
fi
2020-09-22 13:27:34 +00:00
fi
2020-10-02 20:20:54 +00:00
path_conda_windows="${path_conda//\//\\}"
2020-10-02 20:14:17 +00:00
wincmd="miniconda.exe /S /D=C:\\msys64$path_conda_windows"
2020-10-04 19:32:58 +00:00
echo "installing conda: $wincmd"
2020-10-02 20:14:17 +00:00
cmd //c "$wincmd"
2020-10-04 10:13:42 +00:00
export PATH="$path_conda/condabin:$path_conda/Library/bin:$path_conda:$PATH"
2020-09-22 13:27:34 +00:00
fi
2020-09-22 13:36:20 +00:00
2020-10-02 20:32:41 +00:00
echo "path_conda = $path_conda"
2020-10-04 19:32:58 +00:00
echo "conda exec is `which conda`"
source "$path_conda/etc/profile.d/conda.sh"
echo "conda exec is `which conda`"
2020-09-25 13:17:03 +00:00
2020-10-04 19:32:58 +00:00
#$condaexec
2020-09-25 13:17:03 +00:00
2020-10-03 18:07:24 +00:00
2020-09-25 13:17:03 +00:00
2020-09-22 13:26:18 +00:00
2020-10-04 19:32:58 +00:00
############################################################
2020-10-04 08:50:22 +00:00
2020-09-22 13:27:34 +00:00
echo '
2020-09-22 13:26:18 +00:00
5) creating virtual environment...
2020-09-22 13:26:18 +00:00
2020-09-22 13:27:34 +00:00
'
2020-09-25 12:37:13 +00:00
path_venv="$path_repo/venv"
2020-10-02 18:27:27 +00:00
echo "Now using python (t1): `which python`"
2020-10-04 18:14:23 +00:00
2020-10-04 19:32:58 +00:00
conda config --add channels conda-forge
conda create -y -p "$path_venv" python=3.7 cartopy pip virtualenv rtree pyzbar wxpython
# source "$path_conda/etc/profile.d/conda.sh"
2020-10-04 18:14:23 +00:00
2020-10-04 19:32:58 +00:00
conda activate "$path_venv"
2020-10-04 18:14:23 +00:00
2020-10-04 19:32:58 +00:00
echo "Now using python (t2): `which python`"
python -m pip install -U setuptools
2020-10-04 18:14:23 +00:00
2020-09-25 13:17:03 +00:00
2020-10-03 17:58:55 +00:00
2020-10-04 19:32:58 +00:00
###########################################################
2020-09-25 13:17:03 +00:00
2020-10-04 19:32:58 +00:00
echo '
2020-10-04 10:44:13 +00:00
2020-10-04 19:32:58 +00:00
Install python requirements
'
cd $path_repo
python -m pip install -r requirements.txt
2020-10-04 10:44:13 +00:00
2020-10-04 09:49:12 +00:00
2020-09-25 13:17:03 +00:00
2020-10-04 10:13:42 +00:00
2020-10-04 19:32:58 +00:00
#############################################################
2020-10-04 19:39:41 +00:00
# echo '
# Installing other requirements
2020-10-04 19:32:58 +00:00
2020-10-04 19:39:41 +00:00
# Rlite, hardware based redis database
2020-10-04 19:32:58 +00:00
2020-10-04 19:39:41 +00:00
# '
2020-10-04 19:32:58 +00:00
2020-10-04 19:39:41 +00:00
# cd $path_lib
# git clone https://github.com/seppo0010/rlite.git
# cd rlite
# make
# make all
2020-10-04 10:13:42 +00:00
2020-10-04 19:32:58 +00:00
2020-10-04 19:39:41 +00:00
# exit 1
2020-10-04 19:32:58 +00:00
#########################################################################
if [ "$machine" = "Mac" ]
then
echo "Installing Mac native GUI bridge"
python -m pip install git+https://github.com/kivy/pyobjus
2020-10-04 19:43:06 +00:00
fi
2020-10-04 19:32:58 +00:00
#######################################
echo '
Themis, cryptography backend...
'
if [ "$machine" = "Mac" ]
2020-10-04 10:52:04 +00:00
then
2020-10-04 19:32:58 +00:00
echo 'installing themis with brew'
/usr/local/bin/brew tap cossacklabs/tap
/usr/local/bin/brew install libthemis
else
2020-10-04 10:52:04 +00:00
if [ ! -f "/usr/local/lib/libthemis.so" ]
then
if [ ! -f "/usr/lib/libthemis.so" ]
then
2020-10-04 19:32:58 +00:00
echo 'building themis'
2020-10-04 10:52:04 +00:00
cd "$path_lib"
# pwd
2020-10-04 19:32:58 +00:00
#git clone https://github.com/cossacklabs/themis.git
2020-10-04 10:52:04 +00:00
curl https://codeload.github.com/cossacklabs/themis/zip/master -o themis.zip
unzip -q -o themis.zip
#mv themis-master themis
cd themis-master
make
2020-10-04 19:39:41 +00:00
make install
# sudo make install
2020-10-04 10:52:04 +00:00
fi
fi
fi
2020-10-04 10:13:42 +00:00
2020-10-04 08:55:46 +00:00
2020-10-04 10:13:42 +00:00
2020-09-22 13:23:49 +00:00
echo '
2020-09-22 10:02:40 +00:00
2020-10-04 19:32:58 +00:00
Completing...
2020-09-22 10:02:40 +00:00
2020-09-22 13:23:49 +00:00
'
2020-09-14 15:59:11 +00:00
2020-09-27 12:08:32 +00:00
commands_app="
2020-09-28 13:17:52 +00:00
source $path_conda/etc/profile.d/conda.sh\n
export PATH=\"$path_conda/bin:\$PATH\"\n
conda activate $path_venv\n
python -m pip install -r $path_repo/requirements.txt\n
2020-09-29 13:09:56 +00:00
python $path_repo/comrad/app/main.py\n
2020-09-27 12:08:32 +00:00
"
export PATH="$path_bin:$PATH"
2020-09-29 13:09:56 +00:00
bashline="export PATH=\"$path_bin:\$PATH\" # comrad installation"
2020-09-29 15:35:33 +00:00
bashfn="`realpath ~/.bashrc`"
2020-09-27 12:08:32 +00:00
# add to bashrc?
if grep -Fxq "$bashline" "$bashfn"
then
# code if found
echo "setting already in $bashfn: $bashline"
else
# code if not found
echo "$bashline" >> "$bashfn"
fi
2020-09-22 10:02:40 +00:00
2020-09-22 13:36:20 +00:00
2020-09-29 13:09:56 +00:00
echo -e "Now run Comrad with:
2020-09-22 10:02:40 +00:00
2020-09-29 13:09:56 +00:00
comrad-app [GUI interface -- alpha]
2020-09-22 11:16:30 +00:00
If that doesn't work, try running this series of comands:
2020-09-27 12:08:32 +00:00
$commands_app
2020-09-22 13:23:49 +00:00
"
2020-09-28 13:17:52 +00:00
if [ "$machine" = "Mac" ]
then
2020-09-28 13:55:01 +00:00
cd /Applications
2020-10-02 21:06:02 +00:00
unzip -q -o "$path_bin/Comrad.app.zip"
2020-09-29 13:09:56 +00:00
echo "You may run the app by looking for 'Comrad.app' in your /Applications folder."
2020-09-29 06:14:13 +00:00
fi
2020-10-04 10:44:13 +00:00
2020-09-29 06:14:13 +00:00
2020-10-04 19:32:58 +00:00
# run?
. $path_bin/comrad-app