Kovri: vastly improve + fix installation script

- Use correct interpreter
- Create error handler
- Simplify $OSTYPE detection + add DragonFlyBSD
- Backup configuration files if already present
- Remove existing installation if present
- Refactor + fix existing installation methods
- Move binary to dedicated location
- Add BSD-3 license
- Add color output

References:
- monero-project/meta#35
- monero-project/kovri#362
This commit is contained in:
anonimal 2017-02-21 10:18:24 +00:00
parent 39b77b4683
commit d9e25266ef
No known key found for this signature in database
GPG key ID: 66A76ECF914409F1

View file

@ -1,48 +1,127 @@
#!/bin/bash #!/usr/bin/env bash
# TODO(unassigned): /bin/sh isn't smart enough
# Trivial script to install binary/resources using the makeself installer # Copyright (c) 2017, The Kovri I2P Router Project
# Not to substitute real packaging (this is meant for nightly/branch-tip builds) #
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
case "$OSTYPE" in #
linux*) # Kovri installer script: installs binary/resources for nightly/branch-tip builds
#
# Test if terminal is color capable
if [[ $(tput colors) ]]; then
_red="$(tput setaf 1)"
_green="$(tput setaf 2)"
_yellow="$(tput setaf 3)"
_normal="$(tput sgr0)"
fi
_banner="${_yellow}The Kovri I2P Router Project Installer${_normal}"
echo $_banner
# Error handler
catch() {
if [[ $? -ne 0 ]]; then
echo " ${_red}[ERROR] Failed to install: '$1' ${_normal}"
exit 1
fi
echo " ${_green}[OK]${_normal}"
}
# Get platform
case $OSTYPE in
linux* | freebsd* | dragonfly*)
_data="$HOME/.kovri" _data="$HOME/.kovri"
_path="$HOME/.bin"
;; ;;
darwin*) darwin*)
_data="$HOME/Library/Application Support/Kovri" _data="$HOME/Library/Application Support/Kovri"
_path="$HOME/Library/Desktop"
;;
freebsd*)
_data="$HOME/.kovri"
_path="$HOME/bin"
;; ;;
msys) msys)
_data="$APPDATA\\Kovri" _data="$APPDATA/Kovri"
_path="$HOMEPATH\\Desktop"
;; ;;
*) *)
echo "Unsupported platform" false
exit 1 catch "unsupported platform"
;; ;;
esac esac
_backup="${_data}-$(date +%Y.%m.%d)" # TODO(anonimal): we'll probably want to backup using revision hash # Backup existing installation
_binary="kovri" _config=${_data}/config
_kovri_conf=${_config}/kovri.conf
_tunnels_conf=${_config}/tunnels.conf
# Create bin dir if needed if [[ -d $_data ]]; then
[ ! -d "$_path" ] && mkdir "$_path" echo -n "Begin configuration backup..."
if [[ -f $_kovri_conf ]]; then
# Create backup if needed mv "$_kovri_conf" "${_kovri_conf}.bak"
[ -d "$_data" ] && mv "$_data" "$_backup" && [ -f "${_path}/${_binary}" ] && mv "${_path}/${_binary}" "$_backup" fi
if [[ -f $_tunnels_conf ]]; then
# Move resources mv "$_tunnels_conf" "${_tunnels_conf}.bak"
mkdir "$_data" && mv $(ls -A . | grep -v $(basename "$0")) "$_data" && mv "${_data}/${_binary}" "$_path" fi
catch "could not backup configuration"
if [ $? -ne 0 ]; then
echo "Failed to install. See above error messages"
exit 1
fi fi
echo "Kovri binary '$_binary' is in $_path" # Remove existing install
echo "Consider adding $_path to your \$PATH" _core=${_data}/core
_client=${_data}/client
_installed="$_core $_client/address_book/addresses* $_client/certificates"
if [[ -d $_installed ]]; then
echo -n "Removing existing install"
rm -fr $_installed
catch "could not remove existing install"
fi
# Create new install
_path=$HOME/bin
_binary=kovri
if [[ ! -d $_data ]]; then
echo -n "Creating ${_data}"
mkdir "$_data"
catch "could not create $_data"
fi
if [[ ! -d $_path ]]; then
echo -n "Creating ${_path}"
mkdir "$_path"
catch "could not create $_path"
fi
_resources=(client config $_binary)
for _i in ${_resources[@]}; do
if [[ $_i != $_binary ]]; then
echo -n "Copying $_i to $_data"
cp -fR $_i "$_data"
else
echo -n "Copying $_i to $_path"
cp -f $_i "$_path"
fi
catch "could not copy resource"
done
echo "${_green}Installation success!${_normal}"