2022-07-23 22:14:05 +01:00
|
|
|
#!/bin/bash
|
2022-07-23 17:02:05 +01:00
|
|
|
|
2021-12-05 20:01:34 +04:00
|
|
|
set -eu
|
|
|
|
|
2021-11-28 10:08:26 +00:00
|
|
|
APP_NAME="simplex-chat"
|
2022-01-12 01:26:51 +04:00
|
|
|
BIN_DIR="$HOME/.local/bin"
|
|
|
|
BIN_PATH="$BIN_DIR/$APP_NAME"
|
2021-11-28 10:08:26 +00:00
|
|
|
PLATFORM="$(uname)"
|
|
|
|
|
2022-07-23 22:42:07 +01:00
|
|
|
if [ -n "${1:-}" ]; then
|
2022-07-23 17:02:05 +01:00
|
|
|
RELEASE="tag/$1"
|
|
|
|
DOWNLOAD="download/$1"
|
|
|
|
echo "downloading SimpleX Chat $1 ..."
|
|
|
|
else
|
|
|
|
RELEASE=latest
|
|
|
|
DOWNLOAD="latest/download"
|
|
|
|
echo "downloading the latest version of SimpleX Chat ..."
|
|
|
|
fi
|
|
|
|
|
2021-11-28 10:08:26 +00:00
|
|
|
if [ $PLATFORM == "Darwin" ]; then
|
2022-01-12 23:16:05 +04:00
|
|
|
PLATFORM="macos-x86-64"
|
2021-11-28 10:08:26 +00:00
|
|
|
elif [ $PLATFORM == "Linux" ]; then
|
2022-01-12 23:16:05 +04:00
|
|
|
PLATFORM="ubuntu-20_04-x86-64"
|
2021-11-28 10:08:26 +00:00
|
|
|
else
|
2022-01-12 23:16:05 +04:00
|
|
|
echo "Scripted installation on your platform is not supported."
|
2022-07-23 17:02:05 +01:00
|
|
|
echo "See compiled binaries in the ${1:-latest} release: https://github.com/$APP_NAME/$APP_NAME/releases/$RELEASE"
|
2022-01-12 23:16:05 +04:00
|
|
|
exit 1
|
2021-11-28 10:08:26 +00:00
|
|
|
fi
|
|
|
|
|
2022-01-12 01:26:51 +04:00
|
|
|
# / Prepare to upgrade from v0 to v1
|
|
|
|
|
|
|
|
# Determine path of chat binary
|
|
|
|
if [[ -n "$(which $APP_NAME)" ]]; then
|
2022-01-12 23:16:05 +04:00
|
|
|
binary=$(which $APP_NAME)
|
2022-01-12 01:26:51 +04:00
|
|
|
elif [[ -f "$BIN_PATH" ]]; then
|
2022-01-12 23:16:05 +04:00
|
|
|
binary=$BIN_PATH
|
2022-01-12 01:26:51 +04:00
|
|
|
else
|
2022-01-12 23:16:05 +04:00
|
|
|
binary=""
|
2022-01-12 01:26:51 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# If chat binary not found, check v0 initial migration and offer to abort or continue
|
|
|
|
if [[ -z $binary ]]; then
|
2022-01-12 23:16:05 +04:00
|
|
|
agent_db="$HOME/.simplex/simplex.agent.db"
|
|
|
|
if [[ \
|
|
|
|
-f "$agent_db" && \
|
|
|
|
$(echo "select * from migrations;" | sqlite3 $agent_db | grep 20210101_initial) \
|
|
|
|
]]; then
|
|
|
|
echo "Warning: found SimpleX Chat database, the current version is not backwards compatible."
|
|
|
|
echo "If you continue, the current version will be installed as $APP_NAME with a clean database, the old database will be preserved."
|
|
|
|
while true; do
|
|
|
|
read -p "Please choose to (a)bort or (c)ontinue: " yn < /dev/tty
|
|
|
|
case $yn in
|
|
|
|
[Aa]* ) exit 1 ;;
|
|
|
|
[Cc]* ) break ;;
|
|
|
|
* ) echo "Please answer 'a' or 'c'."
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
2022-01-12 01:26:51 +04:00
|
|
|
# If chat binary found, check version and offer to abort or continue, on continue rename chat binary
|
|
|
|
elif [[ ! $($binary -h | grep v1) ]]; then
|
2022-01-12 23:16:05 +04:00
|
|
|
echo "Warning: found a previous version of SimpleX Chat, the current version is not backwards compatible."
|
|
|
|
echo "If you continue, it will be renamed to $APP_NAME-v0, and the new version will be installed as $APP_NAME with a clean database."
|
|
|
|
while true; do
|
|
|
|
read -p "Please choose (a)bort or (c)ontinue: " yn < /dev/tty
|
|
|
|
case $yn in
|
|
|
|
[Aa]* ) exit 1 ;;
|
|
|
|
[Cc]* )
|
|
|
|
binary_v0="$binary-v0"
|
|
|
|
mv ${binary} ${binary_v0}
|
|
|
|
echo "Renamed $binary into $binary_v0"
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
* ) echo "Please answer 'a' or 'c'."
|
|
|
|
esac
|
|
|
|
done
|
2022-01-12 01:26:51 +04:00
|
|
|
fi
|
|
|
|
# Prepare to upgrade from v0 to v1 /
|
|
|
|
|
2022-01-12 23:16:05 +04:00
|
|
|
[[ ! -d $BIN_DIR ]] && mkdir -p $BIN_DIR
|
2021-11-28 10:08:26 +00:00
|
|
|
|
2021-12-05 20:01:34 +04:00
|
|
|
if [ -n "$(command -v curl)" ]; then
|
2022-07-23 17:02:05 +01:00
|
|
|
curl -L -o $BIN_PATH "https://github.com/$APP_NAME/$APP_NAME/releases/$DOWNLOAD/$APP_NAME-$PLATFORM"
|
2021-12-05 20:01:34 +04:00
|
|
|
elif [ -n "$(command -v wget)" ]; then
|
2022-07-23 17:02:05 +01:00
|
|
|
wget -O $BIN_PATH "https://github.com/$APP_NAME/$APP_NAME/releases/$DOWNLOAD/$APP_NAME-$PLATFORM"
|
2021-12-05 20:01:34 +04:00
|
|
|
else
|
2022-01-12 23:16:05 +04:00
|
|
|
echo "Cannot download $APP_NAME - please install curl or wget"
|
|
|
|
exit 1
|
2021-12-05 20:01:34 +04:00
|
|
|
fi
|
|
|
|
|
2022-01-12 01:26:51 +04:00
|
|
|
chmod +x $BIN_PATH
|
2021-11-28 10:08:26 +00:00
|
|
|
|
2022-06-06 17:24:33 +02:00
|
|
|
echo "$APP_NAME installed successfully!"
|
2021-11-28 10:08:26 +00:00
|
|
|
|
2022-01-12 01:26:51 +04:00
|
|
|
if [ -z "$(command -v $APP_NAME)" ]; then
|
2022-01-12 23:16:05 +04:00
|
|
|
if [ -n "$($SHELL -c 'echo $ZSH_VERSION')" ]; then
|
|
|
|
SHELL_FILE="$HOME/.zshrc"
|
|
|
|
elif [ -n "$($SHELL -c 'echo $BASH_VERSION')" ]; then
|
|
|
|
SHELL_FILE="$HOME/.bashrc"
|
|
|
|
else
|
|
|
|
echo "Unknown shell - cannot add $APP_NAME folder to PATH"
|
|
|
|
echo "Please add $BIN_DIR to PATH variable"
|
|
|
|
echo "Or you can run $APP_NAME via full path: $BIN_PATH"
|
|
|
|
fi
|
|
|
|
if [ -n "$SHELL_FILE" ]; then
|
|
|
|
echo "export PATH=\$PATH:$BIN_DIR" >> $SHELL_FILE
|
|
|
|
echo "Source your $SHELL_FILE or open a new shell and type $APP_NAME to run it"
|
|
|
|
fi
|
2021-11-28 10:08:26 +00:00
|
|
|
else
|
2022-01-12 23:16:05 +04:00
|
|
|
echo "Type $APP_NAME in your terminal to run it"
|
2021-11-28 10:08:26 +00:00
|
|
|
fi
|