freedombone/src/freedombone-app-librevault

306 lines
10 KiB
Plaintext
Raw Normal View History

2016-08-24 20:41:57 +02:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Librevault application
#
# License
# =======
#
2016-10-31 17:24:49 +01:00
# Copyright (C) 2014-2016 Bob Mottram <bob@freedombone.net>
2016-08-24 20:41:57 +02:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2016-09-30 11:06:30 +02:00
VARIANTS=''
2016-08-24 20:41:57 +02:00
IN_DEFAULT_INSTALL=0
SHOW_ON_ABOUT=0
2016-08-24 20:41:57 +02:00
PROTOBUF_REPO="https://github.com/google/protobuf"
PROTOBUF_COMMIT='b97a4a53cdd55be74c30badefeb132a091764f53'
LIBREVAULT_REPO="https://github.com/Librevault/librevault"
LIBREVAULT_COMMIT='86a6aefcb5cc458f4d42195368fbcff2871f98e3'
2016-08-26 17:38:53 +02:00
LIBREVAULT_PORT=42345
2016-08-24 20:41:57 +02:00
2016-10-05 23:33:41 +02:00
librevault_variables=(PROTOBUF_REPO
LIBREVAULT_REPO
LIBREVAULT_PORT)
function install_interactive_librevault {
echo -n ''
APP_INSTALLED=1
}
2016-08-24 20:41:57 +02:00
function reconfigure_librevault {
echo -n ''
# TODO
}
function upgrade_librevault {
CURR_LIBREVAULT_COMMIT=$(get_completion_param "librevault commit")
if [[ "$CURR_LIBREVAULT_COMMIT" == "$LIBREVAULT_COMMIT" ]]; then
return
fi
2016-08-26 17:38:53 +02:00
function_check set_repo_commit
if [ -d $INSTALL_DIR/protobuf ]; then
if ! grep -q "Protobuf commit:$PROTOBUF_COMMIT" $COMPLETION_FILE; then
set_repo_commit $INSTALL_DIR/protobuf "Protobuf commit" "$PROTOBUF_COMMIT" $PROTOBUF_REPO
cd $INSTALL_DIR/protobuf
./autogen.sh
./configure
make
make check
make install
ldconfig
fi
fi
if [ -d $INSTALL_DIR/librevault/build ]; then
if ! grep -q "librevault commit:$LIBREVAULT_COMMIT" $COMPLETION_FILE; then
set_repo_commit $INSTALL_DIR/librevault "librevault commit" "$LIBREVAULT_COMMIT" $LIBREVAULT_REPO
2016-08-26 17:38:53 +02:00
cd $INSTALL_DIR/librevault
git submodule update --init --recursive
cd $INSTALL_DIR/librevault/build
cmake ..
cmake --build .
make install
fi
fi
2016-08-24 20:41:57 +02:00
}
function backup_local_librevault {
2016-08-26 17:38:53 +02:00
echo -n ''
2016-08-24 20:41:57 +02:00
# TODO
}
function restore_local_librevault {
2016-08-26 17:38:53 +02:00
echo -n ''
2016-08-24 20:41:57 +02:00
# TODO
}
function backup_remote_librevault {
2016-08-26 17:38:53 +02:00
echo -n ''
2016-08-24 20:41:57 +02:00
# TODO
}
function restore_remote_librevault {
2016-08-26 17:38:53 +02:00
echo -n ''
2016-08-24 20:41:57 +02:00
# TODO
}
function remove_librevault {
2016-10-22 11:39:34 +02:00
firewall_remove ${LIBREVAULT_PORT}
2016-08-24 20:41:57 +02:00
systemctl stop librevault
systemctl disable librevault
rm /etc/systemd/system/librevault.service
2017-06-10 22:37:50 +02:00
systemctl daemon-reload
2016-10-17 15:44:49 +02:00
remove_completion_param install_librevault
remove_completion_param configure_firewall_for_librevault
2016-08-24 20:41:57 +02:00
}
function configure_firewall_for_librevault {
2016-10-16 20:50:56 +02:00
if [[ $(is_completed $FUNCNAME) == "1" ]]; then
2016-08-24 20:41:57 +02:00
return
fi
2016-10-22 11:39:34 +02:00
firewall_add Librevault ${LIBREVAULT_PORT}
2016-10-16 20:50:56 +02:00
mark_completed $FUNCNAME
2016-08-24 20:41:57 +02:00
}
2016-08-24 23:45:45 +02:00
function mesh_install_librevault {
install_tracker
2016-08-26 17:38:53 +02:00
install_cmake
install_cryptopp
2016-08-24 23:45:45 +02:00
2016-10-23 20:38:14 +02:00
chroot "$rootdir" apt-get -yq install bittornado nginx
chroot "$rootdir" apt-get -yq install build-essential
chroot "$rootdir" apt-get -yq install autoconf automake libtool curl make unzip
2016-08-26 17:38:53 +02:00
# A workaround which allows c++14 to be installed
2016-10-23 20:38:14 +02:00
chroot "$rootdir" apt-get -yq install g++ gcc-6 g++-6 libboost-all-dev libssl-dev
chroot "$rootdir" apt-get -yq install protobuf-compiler libprotobuf-dev
chroot "$rootdir" apt-get -yq install qtbase5-dev libqt5svg5-dev libqt5websockets5-dev
chroot "$rootdir" apt-get -yq install libsqlite3-dev qttools5-dev qttools5-dev-tools libnatpmp-dev
2016-08-24 23:45:45 +02:00
if [ ! -d $rootdir$INSTALL_DIR ]; then
2016-08-26 17:38:53 +02:00
mkdir -p $rootdir$INSTALL_DIR
2016-08-24 23:45:45 +02:00
fi
2016-08-26 17:38:53 +02:00
git clone $PROTOBUF_REPO $rootdir$INSTALL_DIR/protobuf
2016-08-24 23:45:45 +02:00
cd $rootdir$INSTALL_DIR/protobuf
git checkout $PROTOBUF_COMMIT -b $PROTOBUF_COMMIT
cat <<EOF > $rootdir/root/install_protobuf
cd $INSTALL_DIR/protobuf
./autogen.sh
./configure
make
make install
ldconfig
EOF
chroot "$rootdir" chmod +x /root/install_protobuf
chroot "$rootdir" /root/install_protobuf
2016-08-26 17:38:53 +02:00
git clone $LIBREVAULT_REPO $rootdir$INSTALL_DIR/librevault
2016-08-24 23:45:45 +02:00
cd $rootdir$INSTALL_DIR/librevault
git checkout $LIBREVAULT_COMMIT -b $LIBREVAULT_COMMIT
2016-08-26 17:38:53 +02:00
git submodule update --init --recursive
# rabin seems particularly broken
rm -rf $rootdir$INSTALL_DIR/librevault/contrib/rabin
git clone https://github.com/bashrc/rabin $rootdir$INSTALL_DIR/librevault/contrib/rabin
cd $rootdir$INSTALL_DIR/librevault/contrib/rabin
git checkout bashrc/fixup2
2016-08-24 23:45:45 +02:00
mkdir $rootdir$INSTALL_DIR/librevault/build
cat <<EOF > $rootdir/root/install_librevault
cd $INSTALL_DIR/librevault/build
2016-08-26 17:38:53 +02:00
cmake -BUILD_UPDATER=OFF ..
which Meta_s.pb.cc
cmake --build $INSTALL_DIR/librevault/build
2016-08-24 23:45:45 +02:00
make install
EOF
chroot "$rootdir" chmod +x /root/install_librevault
chroot "$rootdir" /root/install_librevault
2016-08-26 17:38:53 +02:00
chroot "$rootdir" rm /root/install_librevault
LIBREVAULT_DAEMON=$rootdir/etc/systemd/system/librevault-daemon.service
echo '[Unit]' > $LIBREVAULT_DAEMON
echo 'Description=Librevault - Peer-to-peer, decentralized and open source file sync (multi-instance-master)' >> $LIBREVAULT_DAEMON
echo '' >> $LIBREVAULT_DAEMON
echo '[Service]' >> $LIBREVAULT_DAEMON
echo 'Type=oneshot' >> $LIBREVAULT_DAEMON
echo 'RemainAfterExit=yes' >> $LIBREVAULT_DAEMON
echo 'ExecStart=/bin/true' >> $LIBREVAULT_DAEMON
echo 'ExecReload=/bin/true' >> $LIBREVAULT_DAEMON
echo '' >> $LIBREVAULT_DAEMON
echo '[Install]' >> $LIBREVAULT_DAEMON
echo 'WantedBy=multi-user.target' >> $LIBREVAULT_DAEMON
LIBREVAULT_DAEMON=$rootdir/etc/systemd/system/librevault-daemon@.service
echo '[Unit]' > $LIBREVAULT_DAEMON
echo 'Description=Librevault - Peer-to-peer, decentralized and open source file sync (instance for %I)' >> $LIBREVAULT_DAEMON
echo 'After=network.target' >> $LIBREVAULT_DAEMON
echo 'PartOf=librevault-daemon.service' >> $LIBREVAULT_DAEMON
echo 'ReloadPropagatedFrom=librevault-daemon.service' >> $LIBREVAULT_DAEMON
echo '' >> $LIBREVAULT_DAEMON
echo '[Service]' >> $LIBREVAULT_DAEMON
echo 'User=%i' >> $LIBREVAULT_DAEMON
echo 'ExecStart=/usr/bin/librevault-daemon' >> $LIBREVAULT_DAEMON
echo 'Restart=on-failure' >> $LIBREVAULT_DAEMON
echo '' >> $LIBREVAULT_DAEMON
echo '[Install]' >> $LIBREVAULT_DAEMON
echo 'WantedBy=multi-user.target' >> $LIBREVAULT_DAEMON
chroot "$rootdir" systemctl enable librevault-daemon
2016-08-24 20:41:57 +02:00
}
2016-08-24 23:45:45 +02:00
function install_librevault {
2016-08-24 20:41:57 +02:00
if [ $INSTALLING_MESH ]; then
mesh_install_librevault
return
fi
2016-08-24 23:45:45 +02:00
install_tracker
2016-08-26 17:38:53 +02:00
install_cmake
install_cryptopp
2016-08-24 23:45:45 +02:00
2016-10-23 20:38:14 +02:00
apt-get -yq install build-essential
apt-get -yq install autoconf automake libtool curl make unzip
2016-08-26 17:38:53 +02:00
# A workaround which allows c++14 to be installed
2016-10-23 20:38:14 +02:00
apt-get -yq install protobuf-compiler libprotobuf-dev
apt-get -yq install g++ gcc-6 g++-6 libboost-all-dev libssl-dev
apt-get -yq install qtbase5-dev libqt5svg5-dev libqt5websockets5-dev
apt-get -yq install libsqlite3-dev qttools5-dev qttools5-dev-tools libnatpmp-dev
apt-get -yq install gcc-6 g++-6 libboost-all-dev
2016-08-24 20:41:57 +02:00
if [ ! -d $INSTALL_DIR ]; then
mkdir -p $INSTALL_DIR
fi
git_clone $PROTOBUF_REPO $INSTALL_DIR/protobuf
cd $INSTALL_DIR/protobuf
git checkout $PROTOBUF_COMMIT -b $PROTOBUF_COMMIT
./autogen.sh
./configure
make
make check
make install
ldconfig
2016-10-16 20:50:56 +02:00
set_completion_param "Protobuf commit" "$PROTOBUF_COMMIT"
2016-08-26 17:38:53 +02:00
2016-08-24 20:41:57 +02:00
git_clone $LIBREVAULT_REPO $INSTALL_DIR/librevault
cd $INSTALL_DIR/librevault
git checkout $LIBREVAULT_COMMIT -b $LIBREVAULT_COMMIT
2016-08-26 17:38:53 +02:00
git submodule update --init --recursive
# rabin seems particularly broken
rm -rf $INSTALL_DIR/librevault/contrib/rabin
git clone https://github.com/bashrc/rabin $INSTALL_DIR/librevault/contrib/rabin
cd $INSTALL_DIR/librevault/contrib/rabin
git checkout bashrc/fixup2
2016-08-24 20:41:57 +02:00
mkdir $INSTALL_DIR/librevault/build
cd $INSTALL_DIR/librevault/build
2016-08-26 17:38:53 +02:00
cmake -BUILD_UPDATER=OFF ..
2016-08-24 20:41:57 +02:00
cmake --build .
2016-08-24 23:45:45 +02:00
make install
2016-08-24 20:41:57 +02:00
set_completion_param "librevault commit" "$LIBREVAULT_COMMIT"
2016-08-26 17:38:53 +02:00
LIBREVAULT_DAEMON=/etc/systemd/system/librevault-daemon.service
echo '[Unit]' > $LIBREVAULT_DAEMON
echo 'Description=Librevault - Peer-to-peer, decentralized and open source file sync (multi-instance-master)' >> $LIBREVAULT_DAEMON
echo '' >> $LIBREVAULT_DAEMON
echo '[Service]' >> $LIBREVAULT_DAEMON
echo 'Type=oneshot' >> $LIBREVAULT_DAEMON
echo 'RemainAfterExit=yes' >> $LIBREVAULT_DAEMON
echo 'ExecStart=/bin/true' >> $LIBREVAULT_DAEMON
echo 'ExecReload=/bin/true' >> $LIBREVAULT_DAEMON
echo '' >> $LIBREVAULT_DAEMON
echo '[Install]' >> $LIBREVAULT_DAEMON
echo 'WantedBy=multi-user.target' >> $LIBREVAULT_DAEMON
LIBREVAULT_DAEMON=/etc/systemd/system/librevault-daemon@.service
echo '[Unit]' > $LIBREVAULT_DAEMON
echo 'Description=Librevault - Peer-to-peer, decentralized and open source file sync (instance for %I)' >> $LIBREVAULT_DAEMON
echo 'After=network.target' >> $LIBREVAULT_DAEMON
echo 'PartOf=librevault-daemon.service' >> $LIBREVAULT_DAEMON
echo 'ReloadPropagatedFrom=librevault-daemon.service' >> $LIBREVAULT_DAEMON
echo '' >> $LIBREVAULT_DAEMON
echo '[Service]' >> $LIBREVAULT_DAEMON
echo 'User=%i' >> $LIBREVAULT_DAEMON
echo 'ExecStart=/usr/bin/librevault-daemon' >> $LIBREVAULT_DAEMON
echo 'Restart=on-failure' >> $LIBREVAULT_DAEMON
echo '' >> $LIBREVAULT_DAEMON
echo '[Install]' >> $LIBREVAULT_DAEMON
echo 'WantedBy=multi-user.target' >> $LIBREVAULT_DAEMON
systemctl enable librevault-daemon
systemctl start librevault-daemon
APP_INSTALLED=1
2016-08-24 20:41:57 +02:00
}
# NOTE: deliberately no exit 0