freedombone/src/freedombone-app-librevault

334 lines
11 KiB
Plaintext
Raw Normal View History

2016-08-24 20:41:57 +02:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Librevault application
#
# License
# =======
#
# Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
#
# 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
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
function install_interactive_librevault {
echo -n ''
}
2016-09-25 12:20:41 +02:00
function change_password_librevault {
echo -n ''
}
2016-08-24 20:41:57 +02:00
function reconfigure_librevault {
echo -n ''
# TODO
}
function upgrade_librevault {
2016-08-26 17:38:53 +02:00
if ! grep -Fxq "install_librevault" $COMPLETION_FILE; then
return
fi
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
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 {
if ! grep -Fxq "install_librevault" $COMPLETION_FILE; then
return
fi
2016-08-26 17:38:53 +02:00
iptables -D INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
iptables -D INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
function_check save_firewall_settings
save_firewall_settings
2016-08-24 20:41:57 +02:00
systemctl stop librevault
systemctl disable librevault
rm /etc/systemd/system/librevault.service
sed -i '/install_librevault/d' $COMPLETION_FILE
sed -i '/configure_firewall_for_librevault/d' $COMPLETION_FILE
}
function configure_firewall_for_librevault {
if grep -Fxq "configure_firewall_for_librevault" $COMPLETION_FILE; then
return
fi
2016-08-26 17:38:53 +02:00
iptables -A INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
iptables -A INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
function_check save_firewall_settings
save_firewall_settings
OPEN_PORTS+=("Librevault $LIBREVAULT_PORT")
2016-08-24 20:41:57 +02:00
echo 'configure_firewall_for_librevault' >> $COMPLETION_FILE
}
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
chroot "$rootdir" apt-get -y install bittornado nginx
2016-08-26 17:38:53 +02:00
chroot "$rootdir" apt-get -y install build-essential
chroot "$rootdir" apt-get -y install autoconf automake libtool curl make unzip
# A workaround which allows c++14 to be installed
sed -i 's|jessie|stretch|g' $rootdir/etc/apt/sources.list
sed -i 's|stretch-backports|jessie-backports|g' $rootdir/etc/apt/sources.list
chroot "$rootdir" apt-get update
chroot "$rootdir" apt-get -y install g++ gcc-6 g++-6 libboost-all-dev libssl-dev
chroot "$rootdir" apt-get -y install protobuf-compiler libprotobuf-dev
2016-08-24 23:45:45 +02:00
chroot "$rootdir" apt-get -y install qtbase5-dev libqt5svg5-dev libqt5websockets5-dev
2016-08-26 17:38:53 +02:00
chroot "$rootdir" apt-get -y install libsqlite3-dev qttools5-dev qttools5-dev-tools libnatpmp-dev
sed -i 's|stretch|jessie|g' $rootdir/etc/apt/sources.list
chroot "$rootdir" apt-get update
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-09-30 17:00:45 +02:00
if [[ $(app_is_installed librevault) == "1" ]]; then
2016-08-24 20:41:57 +02:00
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-08-26 17:38:53 +02:00
apt-get -y install build-essential
apt-get -y install autoconf automake libtool curl make unzip
# A workaround which allows c++14 to be installed
sed -i 's|jessie|stretch|g' /etc/apt/sources.list
sed -i 's|stretch-backports|jessie-backports|g' /etc/apt/sources.list
apt-get update
apt-get -y install protobuf-compiler libprotobuf-dev
apt-get -y install g++ gcc-6 g++-6 libboost-all-dev libssl-dev
2016-08-24 20:41:57 +02:00
apt-get -y install qtbase5-dev libqt5svg5-dev libqt5websockets5-dev
2016-08-26 17:38:53 +02:00
apt-get -y install libsqlite3-dev qttools5-dev qttools5-dev-tools libnatpmp-dev
apt-get -y install gcc-6 g++-6 libboost-all-dev
sed -i 's|stretch|jessie|g' /etc/apt/sources.list
apt-get update
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-08-26 17:38:53 +02:00
if ! grep -q "Protobuf commit" $COMPLETION_FILE; then
echo "Protobuf commit:$PROTOBUF_COMMIT" >> $COMPLETION_FILE
else
sed -i "s/Protobuf commit.*/Protobuf commit:$PROTOBUF_COMMIT/g" $COMPLETION_FILE
fi
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
2016-08-26 17:38:53 +02:00
if ! grep -q "Librevault commit" $COMPLETION_FILE; then
echo "Librevault commit:$LIBREVAULT_COMMIT" >> $COMPLETION_FILE
else
sed -i "s/Librevault commit.*/Librevault commit:$LIBREVAULT_COMMIT/g" $COMPLETION_FILE
fi
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
2016-09-30 17:00:45 +02:00
install_completed librevault
2016-08-24 20:41:57 +02:00
}
# NOTE: deliberately no exit 0