Browse Source

WIP: A first stab at getting the script out and done

master
Luke Murphy 5 years ago
commit
ea57dea11e
No known key found for this signature in database GPG Key ID: 5E2EF5A63E3718CC
  1. 5
      README.md
  2. 281
      bibliotecha.sh

5
README.md

@ -0,0 +1,5 @@
# bibliotecha-install
The script to install Bibliotecha.
> https://install.bibliotecha.info

281
bibliotecha.sh

@ -0,0 +1,281 @@
#!/bin/bash
# ____ _ _ _ _ _ _
# | _ \(_) | | (_) | | | |
# | |_) |_| |__ | |_ ___ | |_ ___ ___| |__ __ _
# | _ <| | '_ \| | |/ _ \| __/ _ \/ __| '_ \ / _` |
# | |_) | | |_) | | | (_) | || __/ (__| | | | (_| |
# |____/|_|_.__/|_|_|\___/ \__\___|\___|_| |_|\__,_|
#
# Digital books need libraries too
#
# This install script is intended for use with Debian based
# distributions. More specifically, Debian Stretch, which is
# currently the latest distribution release from the Debian
# project.
#
# License
# =======
#
# Copyright (C) 2019 Bibliotecha Contributors <info@varia.zone>
#
# 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/>.
#
# Thanks
# =====
#
# This script is based on the good work of the Freedombone project:
# https://code.freedombone.net/bashrc/freedombone/src/stretch/src/freedombone
APT_CMD="apt -q"
APT_INSTALL_CMD="$APT_CMD install -y --no-install-recommends"
function await_any_key {
echo ""
# shellcheck disable=SC2034
read -n1 -rsp $"Press any key to continue ..." key
echo ""
}
function ensure_root_account {
echo "Checking user account ..."
if ! id | grep -q root; then
echo ""
echo "This script must be run as root"
echo "You can switch to the root user account with:"
echo "$ sudo -i"
echo ""
exit 0
fi
}
function show_bibliotecha_banner {
echo ""
echo " ____ _ _ _ _ _ _ "
echo " | _ \(_) | | (_) | | | |"
echo " | |_) |_| |__ | |_ ___ | |_ ___ ___| |__ __ _ "
echo " | _ <| | '_ \| | |/ _ \| __/ _ \/ __| '_ \ / _' |"
echo " | |_) | | |_) | | | (_) | || __/ (__| | | | (_| |"
echo " |____/|_|_.__/|_|_|\___/ \__\___|\___|_| |_|\__,_|"
echo ""
echo " Digital books need libraries too"
echo ""
}
function show_introduction_text {
echo ""
echo "Welcome to the Bibliotecha installation script"
echo ""
echo "This script will setup the following infrastructure:"
echo ""
echo "* A Python 3 environment"
echo "* A Wifi hotspot, DNS server and DHCP service"
echo "* A Lighttpd web server"
echo "* A Calibre server"
echo "* A Calibre-web service"
echo ""
echo "Once the script is finished, please see post-install steps"
echo "that are documented and available from the Bibliotecha manual:"
echo ""
echo " https://manual.bibliotecha.info/#TODO"
echo ""
await_any_key
}
function ensure_stretch_based_distribution {
echo "Checking distribution ..."
local installing_on_stretch_based=1
if [ ! -f /usr/bin/foobar ]; then
installing_on_stretch_based=
fi
if [ ! -f /etc/apt/sources.list ]; then
installing_on_stretch_based=
else
if ! grep -q 'stretch' /etc/apt/sources.list; then
installing_on_stretch_based=
fi
if ! grep -q 'debian' /etc/apt/sources.list; then
if ! grep -q 'raspbian' /etc/apt/sources.list; then
installing_on_stretch_based=
fi
fi
fi
if [ ! $installing_on_stretch_based ]; then
echo $"You should only run this on a Debian Stretch based system"
exit 0
fi
}
function run_apt_update {
echo "Running a package listing update ..."
$APT_CMD update
}
function install_networking_packages {
echo "Installing networking packages ..."
$APT_INSTALL_CMD \
dhcpcd \
dnsmasq \
dnsutils \
hostapd \
wireless-tools
}
function disable_networking_services {
echo "Stopping the networking services ..."
local services="dnsmasq hostapd"
systemctl stop ${services}
}
function ensure_variable_set {
local variable="${1}"
if [[ -z "${variable}" ]]; then
echo $"${variable} is not set. Cannot proceed ..."
exit 1
fi
}
function configure_network_interfaces {
echo "Configuring networking interfaces ..."
ethernet_interface=$(ls /sys/class/net/ | grep foo)
local ethernet_filename="/etc/network/interfaces.d/${ethernet_interface}"
if [[ -z "${ethernet_interface}" ]]; then
echo ""
echo "Could not determine the ethernet interface"
echo "Please ensure you've configure 'predictable network interfaces'"
echo "Please see #TODO for more"
echo ""
exit 1
fi
{ echo "auto eth0";
echo "allow-hotplug ${ethernet_interface}";
echo "iface ${ethernet_interface} inet dhcp"; } > "${ethernet_filename}"
local wireless_interface=$(ls /sys/class/net/ | grep wl)
local wireless_filename="/etc/network/interfaces.d/${wireless_interface}"
if [[ -z "${wireless_interface}" ]]; then
echo ""
echo "Could not determine the wireless interface"
echo "Please ensure you've configure 'predictable network interfaces'"
echo "Please see #TODO for more"
echo ""
exit 1
fi
{ echo "auto ${wireless_interface}";
echo "iface ${wireless_interface} int static";
echo " address 10.0.0.1";
echo " netmask 255.255.255.0"; } > "${wireless_filename}"
}
function configure_dnsmasq {
echo "Configuring dnsmasq ..."
local wireless_interface=$(ls /sys/class/net/ | grep wl)
local wireless_filename="/etc/dnsmasq.d/${wireless_interface}.conf"
if [[ -z "${wireless_interface}" ]]; then
echo ""
echo "Could not determine the wireless interface"
echo "Please ensure you've configure 'predictable network interfaces'"
echo "Please see #TODO for more"
echo ""
exit 1
fi
{ echo "bogus-priv"
echo "server=/library/10.0.0.1"
echo "local=/library/"
echo "address=/#/10.0.0.1"
echo "interface=${wireless_interface}"
echo "domain=library"
echo "dhcp-range=10.0.0.50,10.0.0.200,255.255.255.0,12h"
echo "dhcp-option=3,10.0.0.1"
echo "dhcp-option=6,10.0.0.1"
echo "dhcp-authoritative"; } > "${wireless_filename}"
}
function configure_hostapd {
echo "Configuring hostapd ..."
local wireless_interface=$(ls /sys/class/net/ | grep wl)
local hostapd_filename="/etc/hostapd/hostapd.conf"
if [[ -z "${wireless_interface}" ]]; then
echo ""
echo "Could not determine the wireless interface"
echo "Please ensure you've configure 'predictable network interfaces'"
echo "Please see #TODO for more"
echo ""
exit 1
fi
{ echo "interface=${wireless_interface}"
echo "ssid=Bibliotecha"
echo "hw_mode=g"
echo "channel=11"
echo "auth_algs=1"; } > "${hostapd_filename}"
sed -i \
's/#DAEMON_CONF=""/DAEMON_CONF="\/etc\/hostapd\/hostapd.conf"/g' \
/etc/default/hostapd
}
function enable_networking_services {
echo "Enabling network services ..."
local services="dnsmasq hostapd"
systemctl unmask hostapd
systemctl enable ${services}
}
function run_installation {
#ensure_root_account
#ensure_stretch_based_distribution
#show_bibliotecha_banner
#show_introduction_text
#run_apt_update
#install_networking_packages
#disable_networking_services
#configure_network_interfaces
#configure_dnsmasq
#configure_hostapd
#enable_networking_services
# TODO
# install lighttpd and configure it
# install calibre web and configure it
# setup drone and make sure things are being tested
}
run_installation
exit 0
Loading…
Cancel
Save