2
0
mirror of https://github.com/ComradCollective/Comrad synced 2024-11-16 00:12:48 +00:00
Comrad/script/install

350 lines
6.9 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-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-09-14 13:38:27 +00:00
# # ## # # ### ## ### ####
# # # # #### # # # # # # #
## # # #### ### # # # # ###
# # # # # # # # #### # # #
# # ## # # # # # # ### ####
2020-09-14 15:59:11 +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
echo '
1) setting up folder...
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-09-29 13:09:56 +00:00
path_bin="$path_comrad/code/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 15:59:11 +00:00
echo '
2020-09-14 16:01:38 +00:00
2020-09-29 13:09:56 +00:00
2) downloading Comrad...
2020-09-14 16:01:38 +00:00
2020-09-14 15:59:11 +00:00
'
2020-09-29 13:09:56 +00:00
path_repo="$path_comrad/code"
2020-09-14 16:56:54 +00:00
if command -v git &> /dev/null
2020-09-14 15:59:11 +00:00
then
2020-09-14 17:01:36 +00:00
echo "using git..."
2020-09-14 16:52:59 +00:00
if [ -d "$path_repo" ]
2020-09-14 15:59:11 +00:00
then
cd $path_repo
git pull
else
2020-09-29 13:09:56 +00:00
cd $path_comrad
2020-09-14 18:49:14 +00:00
2020-09-28 12:59:24 +00:00
if [ "$1" = "-n" ]
2020-09-28 12:42:29 +00:00
then
echo "Use HTTPS or SSH for git?"
read -p "[HTTPS/ssh] " git_method
else
git_method="https"
fi
2020-09-17 05:01:59 +00:00
if [ "$git_method" = "ssh" ]
2020-09-14 18:49:14 +00:00
then
echo "using ssh..."
2020-09-29 13:16:50 +00:00
git clone git@github.com:ComradCollective/Comrad.git
2020-09-22 13:38:52 +00:00
git checkout installer
2020-09-14 18:49:14 +00:00
else
2020-09-29 13:16:50 +00:00
git clone https://github.com/ComradCollective/Comrad.git
2020-09-22 13:38:52 +00:00
git checkout installer
2020-09-14 18:49:14 +00:00
fi
2020-09-29 13:09:56 +00:00
mv Comrad code
2020-09-14 15:59:11 +00:00
fi
else
2020-09-29 13:09:56 +00:00
cd $path_comrad
2020-09-29 13:16:50 +00:00
curl -s -LO https://github.com/ComradCollective/Comrad/archive/installer.zip
2020-09-22 13:38:52 +00:00
unzip installer.zip
rm installer.zip
2020-09-29 13:09:56 +00:00
cp -rT Comrad-installer code
rm -r Comrad-installer
2020-09-14 15:59:11 +00:00
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-09-14 16:01:38 +00:00
echo '
4) setting up python...
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-09-29 13:09:56 +00:00
cd $path_comrad
2020-09-22 13:26:18 +00:00
2020-09-29 13:09:56 +00:00
path_conda="$path_comrad/lib/miniconda3"
2020-09-22 13:27:34 +00:00
# ### Detect if python 3.7?
# pyv="$(python3 -c 'import sys; print(sys.version_info[0:2])')"
# if [ ! "$pyv" = "(3, 7)" ]
2020-09-22 13:26:18 +00:00
# then
2020-09-22 13:27:34 +00:00
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
*) machine="UNKNOWN:${unameOut}"
esac
#echo ${machine}
if [ "$machine" = "Linux" ]
then
2020-09-25 11:50:43 +00:00
if [ ! -f "miniconda.sh" ]
then
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-09-27 12:08:32 +00:00
### install themis from source
if [ ! -f "/usr/local/lib/libthemis.so" ]
then
if [ ! -f "/usr/lib/libthemis.so" ]
then
echo '
3) building Themis, cryptography backend...
'
cd "$path_lib"
# pwd
git clone https://github.com/cossacklabs/themis.git
cd themis
make
sudo make install
fi
fi
### install zbar library
sudo apt install zbar-tools
2020-09-22 13:36:20 +00:00
fi
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
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-09-25 11:50:43 +00:00
# rm miniconda.sh
2020-09-27 12:08:32 +00:00
2020-09-28 12:56:29 +00:00
if command -v /usr/local/bin/brew &> /dev/null
then
cd "$path_lib"
mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
fi
2020-09-27 12:08:32 +00:00
# brew install
2020-09-28 12:56:29 +00:00
/usr/local/bin/brew tap cossacklabs/tap
/usr/local/bin/brew install libthemis
2020-09-27 12:08:32 +00:00
# install zbar library
2020-09-28 12:56:29 +00:00
/usr/local/bin/brew install zbar
2020-09-27 12:08:32 +00:00
2020-09-22 13:36:20 +00:00
fi
if [ "$machine" = "Cygwin" ]
2020-09-22 13:27:34 +00:00
then
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:26:18 +00:00
2020-09-25 11:44:39 +00:00
./miniconda.exe -b -f -p "$path_conda"
2020-09-25 11:50:43 +00:00
# rm miniconda.exe
2020-09-27 12:08:32 +00:00
### install themis from source
if [ ! -f "/usr/local/lib/libthemis.so" ]
then
if [ ! -f "/usr/lib/libthemis.so" ]
then
echo '
3) building Themis, cryptography backend...
'
cd "$path_lib"
# pwd
git clone https://github.com/cossacklabs/themis.git
cd themis
make
sudo make install
fi
fi
### install zbar using apt-cyg
# installing apt-cyg
if ! command -v apt-cyg &> /dev/null
then
echo "installing apt-cyg"
lynx -source https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg > apt-cyg
install apt-cyg /bin
fi
# installing zbar
apt-cyg install zbar
2020-09-22 13:27:34 +00:00
fi
2020-09-22 13:36:20 +00:00
2020-09-25 11:44:39 +00:00
2020-09-25 13:17:03 +00:00
2020-09-25 11:44:39 +00:00
# activate conda
2020-09-25 11:50:43 +00:00
export PATH="$path_conda/bin:$PATH"
2020-09-25 13:17:03 +00:00
source "$path_conda/etc/profile.d/conda.sh"
2020-09-25 11:50:43 +00:00
condaexec="conda"
pythonexec="python"
2020-09-22 13:26:18 +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-09-22 13:26:18 +00:00
2020-09-29 13:09:56 +00:00
# cd $path_comrad
2020-09-25 11:33:02 +00:00
cd $path_repo
echo "Now using python 1: `which python`"
2020-09-25 12:49:38 +00:00
$condaexec create -y -p "$path_venv" python=3.7 cartopy pip virtualenv
2020-09-25 13:17:03 +00:00
#$condaexec activate "$path_venv"
2020-09-25 11:33:02 +00:00
echo "Now using python 2: `which python`"
# $pythonexec -m pip install virtualenv
2020-09-25 12:10:13 +00:00
# $pythonexec -m virtualenv venv
# . venv/bin/activate
2020-09-25 11:33:02 +00:00
echo "Now using python 3: `which python`"
2020-09-22 13:45:46 +00:00
2020-09-22 13:27:34 +00:00
python -m pip install -r requirements.txt
2020-09-22 10:02:40 +00:00
2020-09-22 13:23:49 +00:00
echo '
2020-09-22 10:02:40 +00:00
2020-09-29 13:09:56 +00:00
6) adding comrad bin folder to path
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-27 12:08:32 +00:00
bashfn="~/.bashrc"
# 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-09-29 13:09:56 +00:00
unzip "$path_bin/Comrad.app.zip"
# cp "$path_bin/Comrad.app" /Applications/
2020-09-28 13:17:52 +00:00
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
# run?
2020-09-29 13:09:56 +00:00
. $path_bin/comrad-app
2020-09-29 06:14:13 +00:00
if [ "$machine" = "Mac" ]
then
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-28 13:17:52 +00:00
fi