-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·121 lines (98 loc) · 3.51 KB
/
setup.sh
File metadata and controls
executable file
·121 lines (98 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
# TELEGRAM SERVER (telegram-server)
# setup script to install dependencies and configure environment
stringContains () { [ -z "${2##*$1*}" ]; }
check_libreadline () {
# fix for a very specific type of error
ls /usr/local/opt/readline/lib/libreadline.6.dylib
if [ "$?" == "1" ]; then readline
rm -rf /usr/local/opt/
ln -s ${READLINE_BASE_DIR} /usr/local/opt/readline
fi
}
if [ "$1" != "skip-cli" ]; then
########### PHASE 1: MAKING THE CLI FOR THE AI TO SEND/RECEIVE MSGS ##########
git clone --recursive https://github.com/vysheng/tg.git
cd tg
sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev libpython-dev
if [ "$?" != "0" ] && stringContains "Darwin" `uname` ; then
# pretty safe to say that we're on an OSX, so do all the OSX thingy
# if we're not then too bad, but no harm
brew install libconfig readline lua libevent jansson libgcrypt
READLINE_VERSION=`ls /usr/local/Cellar/readline`
READLINE_VERSION=(${READLINE_VERSION// / })
READLINE_VERSION=${READLINE_VERSION[@]:(-1)}
READLINE_BASE_DIR=/usr/local/Cellar/readline/${READLINE_VERSION}
export CFLAGS="-I/usr/local/include -I${READLINE_BASE_DIR}/include"
export LDFLAGS="-L/usr/local/lib -L${READLINE_BASE_DIR}/lib"
else
echo "Not on mac/darwin but no apt-get"
fi
./configure
sed -i '' 's/ -Werror / /' Makefile
make
###############################################################################
else
echo "Skipping telegram-cli installation..."
fi
if [ "$1" != "skip-python" ]; then
########### PHASE 2: MAKING THE CLI FOR THE AI TO SEND/RECEIVE MSGS ##########
# check if we have python3 installed first
REQUIRED_PYTHON3_VERSION=3
PYTHON3_VERSION=`python3 --version`
if [ "$?" == "127" ] || ! stringContains "${REQUIRED_PYTHON3_VERSION}" "${PYTHON3_VERSION}" ; then
# no py3
echo "Could not locate Python ${REQUIRED_PYTHON3_VERSION}"
echo "Python >= ${REQUIRED_PYTHON3_VERSION} has to be installed to proceed. Install Python ${REQUIRED_PYTHON3_VERSION} on this machine? (y/n):"
read INSTALL_PYTHON
if [ "${INSTALL_PYTHON}" == "y" ]; then
# install py3 - currently only linux or OSX path...
sudo apt-get install python${REQUIRED_PYTHON3_VERSION}
if [ "$?" == "127" ]; then
brew install python3
fi
else
echo 'Aborting setup'
exit 1
fi
fi
pip3 --version
if [ "$?" != "0" ]; then
sudo apt install python3-pip
fi
echo 'Initializing setup...'
echo 'Please input Telegram api_id: '
read -s TG_API_ID
echo 'Please input Telegram api_hash: '
read -s TG_API_HASH
echo 'Generating folders'
mkdir creds
rm creds/telegram.json
mkdir sessions
echo 'Generating credentials file'
echo "{\"api_id\": ${TG_API_ID}, \"api_hash\": \"${TG_API_HASH}\"}" >> creds/telegram.json
python3 -m venv virtualenv
if [ "$?" != "0" ] && stringContains "Linux" `uname` ; then
# Linux/Ubuntu issues
export LC_CTYPE=en_US.utf8
rm -rf virtualenv
pip3 install virtualenv
virtualenv virtualenv
fi
source virtualenv/bin/activate
pip install -r requirements.txt
###############################################################################
else
echo "Skipping python requirements installation..."
fi
if [ "$?" != "0" ] && stringContains "Linux" `uname` ; then
sudo apt-get install redis-server
sudo echo 'maxmemory 128mb\
maxmemory-policy allkeys-lru' >> /etc/redis/redis.conf
else
brew install redis
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
sudo echo 'maxmemory 128mb\
maxmemory-policy allkeys-lru' >> /usr/local/etc/redis.conf
fi