|
|
@ -40,6 +40,11 @@ |
|
|
|
APT_CMD="apt -q" |
|
|
|
APT_INSTALL_CMD="$APT_CMD install -y --no-install-recommends" |
|
|
|
|
|
|
|
CALIBRE_DATABASE_PATH="/opt/calibre-database" |
|
|
|
CAPTIVE_PORTAL_PATH="/var/www/bibliotecha" |
|
|
|
CALIBRE_WEB_PATH="/var/www/calibre-web" |
|
|
|
LIGHTTPD_CONFIG_PATH="/etc/lighttpd/bibliotecha" |
|
|
|
|
|
|
|
function await_any_key { |
|
|
|
echo "" |
|
|
|
# shellcheck disable=SC2034 |
|
|
@ -99,10 +104,6 @@ function ensure_stretch_based_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 |
|
|
@ -117,8 +118,9 @@ function ensure_stretch_based_distribution { |
|
|
|
fi |
|
|
|
|
|
|
|
if [ ! $installing_on_stretch_based ]; then |
|
|
|
echo $"You should only run this on a Debian Stretch based system" |
|
|
|
exit 0 |
|
|
|
echo "You should only run this on a Debian Stretch based system" |
|
|
|
echo "Cannot continue ..." |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
@ -144,22 +146,15 @@ function disable_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 |
|
|
|
systemctl stop "${services}" |
|
|
|
} |
|
|
|
|
|
|
|
function configure_network_interfaces { |
|
|
|
echo "Configuring networking interfaces ..." |
|
|
|
|
|
|
|
ethernet_interface=$(ls /sys/class/net/ | grep foo) |
|
|
|
# shellcheck disable=SC2010 |
|
|
|
# shellcheck disable=SC2155 |
|
|
|
ethernet_interface=$(ls /sys/class/net/ | grep en) |
|
|
|
local ethernet_filename="/etc/network/interfaces.d/${ethernet_interface}" |
|
|
|
|
|
|
|
if [[ -z "${ethernet_interface}" ]]; then |
|
|
@ -175,6 +170,8 @@ function configure_network_interfaces { |
|
|
|
echo "allow-hotplug ${ethernet_interface}"; |
|
|
|
echo "iface ${ethernet_interface} inet dhcp"; } > "${ethernet_filename}" |
|
|
|
|
|
|
|
# shellcheck disable=SC2010 |
|
|
|
# shellcheck disable=SC2155 |
|
|
|
local wireless_interface=$(ls /sys/class/net/ | grep wl) |
|
|
|
local wireless_filename="/etc/network/interfaces.d/${wireless_interface}" |
|
|
|
|
|
|
@ -196,6 +193,8 @@ function configure_network_interfaces { |
|
|
|
function configure_dnsmasq { |
|
|
|
echo "Configuring dnsmasq ..." |
|
|
|
|
|
|
|
# shellcheck disable=SC2010 |
|
|
|
# shellcheck disable=SC2155 |
|
|
|
local wireless_interface=$(ls /sys/class/net/ | grep wl) |
|
|
|
local wireless_filename="/etc/dnsmasq.d/${wireless_interface}.conf" |
|
|
|
|
|
|
@ -223,6 +222,8 @@ function configure_dnsmasq { |
|
|
|
function configure_hostapd { |
|
|
|
echo "Configuring hostapd ..." |
|
|
|
|
|
|
|
# shellcheck disable=SC2010 |
|
|
|
# shellcheck disable=SC2155 |
|
|
|
local wireless_interface=$(ls /sys/class/net/ | grep wl) |
|
|
|
local hostapd_filename="/etc/hostapd/hostapd.conf" |
|
|
|
|
|
|
@ -252,28 +253,147 @@ function enable_networking_services { |
|
|
|
local services="dnsmasq hostapd" |
|
|
|
|
|
|
|
systemctl unmask hostapd |
|
|
|
systemctl enable ${services} |
|
|
|
systemctl enable "${services}" |
|
|
|
} |
|
|
|
|
|
|
|
function install_webserver { |
|
|
|
echo "Installing lighttpd ..." |
|
|
|
|
|
|
|
$APT_INSTALL_CMD lighttpd |
|
|
|
} |
|
|
|
|
|
|
|
function configure_webserver { |
|
|
|
echo "Configuring bibliotecha under lighttpd ..." |
|
|
|
|
|
|
|
if ! grep -q bibliotecha /etc/lighttpd/lighttpd.conf; then |
|
|
|
echo "" |
|
|
|
echo 'include "bibliotecha/bibliotecha.conf"' >> /etc/lighttpd/lighttpd.conf |
|
|
|
fi |
|
|
|
|
|
|
|
mkdir -p "$LIGHTTPD_CONFIG_PATH" |
|
|
|
|
|
|
|
{ echo 'server.error-handler-404 = "/bibliotecha/index.html"' |
|
|
|
echo "" |
|
|
|
# shellcheck disable=SC2016 |
|
|
|
echo '$HTTP["host"] = "bibliotecha.library" {' |
|
|
|
echo ' proxy.server = ("" => (("host" => "127.0.0.1", "port" => "8083")))' |
|
|
|
echo '}'; } > "$LIGHTTPD_CONFIG_PATH/bibliotecha.conf" |
|
|
|
} |
|
|
|
|
|
|
|
function configure_captive_portal { |
|
|
|
echo "Configuring the captive portal page ..." |
|
|
|
|
|
|
|
$APT_INSTALL_CMD wget |
|
|
|
|
|
|
|
captive_portal_url="https://git.vvvvvvaria.org/varia/bibliotecha-captive-portal/raw/branch/master/index.html" |
|
|
|
|
|
|
|
mkdir -p "$CAPTIVE_PORTAL_PATH" |
|
|
|
wget "$captive_portal_url" -O "$CAPTIVE_PORTAL_PATH/index.html" |
|
|
|
chown -R www-data: "$CAPTIVE_PORTAL_PATH" |
|
|
|
} |
|
|
|
|
|
|
|
function install_calibre { |
|
|
|
echo "Install Calibre ..." |
|
|
|
|
|
|
|
$APT_INSTALL_CMD calibre |
|
|
|
} |
|
|
|
|
|
|
|
function configure_calibre_database { |
|
|
|
echo "Configuring the Calibre database ..." |
|
|
|
|
|
|
|
mkdir -p "$CALIBRE_DATABASE_PATH" |
|
|
|
} |
|
|
|
|
|
|
|
function install_calibreweb { |
|
|
|
echo "Installing Calibre-web ..." |
|
|
|
|
|
|
|
$APT_INSTALL_CMD git python3 python3-pip python3-dev python3-venv |
|
|
|
|
|
|
|
# TODO(decentral1se): So, we're temporarily forking calibre-web because we |
|
|
|
# ran into https://github.com/janeczku/calibre-web/issues/951. Hopefully this |
|
|
|
# is resolved soon and we can continue on the regular upstream |
|
|
|
calibre_web_url="https://github.com/decentral1se/calibre-web" |
|
|
|
calibre_web_temp_branch="bibliotecha/temp-fork" |
|
|
|
|
|
|
|
if [ ! -d "$CALIBRE_WEB_PATH" ]; then |
|
|
|
git clone "$calibre_web_url" "$CALIBRE_WEB_PATH" |
|
|
|
cd "$CALIBRE_WEB_PATH" && \ |
|
|
|
git fetch origin && \ |
|
|
|
git checkout "origin/$calibre_web_temp_branch" |
|
|
|
fi |
|
|
|
|
|
|
|
if [ ! -d "$CALIBRE_WEB_PATH/.venv" ]; then |
|
|
|
# shellcheck disable=SC1091 |
|
|
|
cd "$CALIBRE_WEB_PATH" && \ |
|
|
|
python3 -m venv .venv && \ |
|
|
|
.venv/bin/pip install -r requirements.txt |
|
|
|
fi |
|
|
|
|
|
|
|
chown -R www-data: "$CALIBRE_WEB_PATH" |
|
|
|
} |
|
|
|
|
|
|
|
function configure_calibreweb { |
|
|
|
echo "Configuring Calibre-web ..." |
|
|
|
|
|
|
|
{ echo "Description=Calibre-Web" |
|
|
|
echo "" |
|
|
|
echo "[Service]" |
|
|
|
echo "Type=simple" |
|
|
|
echo "User=root" |
|
|
|
echo "ExecStart=$CALIBRE_WEB_PATH/.venv/bin/python $CALIBRE_WEB_PATH/cps.py" |
|
|
|
echo "WorkingDirectory=$CALIBRE_WEB_PATH" |
|
|
|
echo "" |
|
|
|
echo "[Install]" |
|
|
|
echo "WantedBy=multi-user.target"; } > /etc/systemd/system/cps.service |
|
|
|
|
|
|
|
systemctl enable cps.service |
|
|
|
} |
|
|
|
|
|
|
|
function show_post_install_banner { |
|
|
|
echo "" |
|
|
|
echo "Installation complete!" |
|
|
|
echo "" |
|
|
|
echo "The system will now reboot" |
|
|
|
echo "Please see the manual for post-installation tasks" |
|
|
|
echo "And help with troubleshooting the network configuration" |
|
|
|
echo "" |
|
|
|
echo " https://manual.bibliotecha.info/#TODO" |
|
|
|
echo "" |
|
|
|
} |
|
|
|
|
|
|
|
function reboot_system { |
|
|
|
echo "Rebooting system ..." |
|
|
|
|
|
|
|
reboot |
|
|
|
} |
|
|
|
|
|
|
|
function run_installation { |
|
|
|
#ensure_root_account |
|
|
|
#ensure_stretch_based_distribution |
|
|
|
ensure_root_account |
|
|
|
ensure_stretch_based_distribution |
|
|
|
|
|
|
|
show_bibliotecha_banner |
|
|
|
show_introduction_text |
|
|
|
|
|
|
|
run_apt_update |
|
|
|
|
|
|
|
#show_bibliotecha_banner |
|
|
|
#show_introduction_text |
|
|
|
install_networking_packages |
|
|
|
disable_networking_services |
|
|
|
configure_network_interfaces |
|
|
|
configure_dnsmasq |
|
|
|
configure_hostapd |
|
|
|
enable_networking_services |
|
|
|
|
|
|
|
#run_apt_update |
|
|
|
install_webserver |
|
|
|
configure_webserver |
|
|
|
configure_captive_portal |
|
|
|
|
|
|
|
#install_networking_packages |
|
|
|
#disable_networking_services |
|
|
|
#configure_network_interfaces |
|
|
|
#configure_dnsmasq |
|
|
|
#configure_hostapd |
|
|
|
#enable_networking_services |
|
|
|
install_calibre |
|
|
|
configure_calibre_database |
|
|
|
install_calibreweb |
|
|
|
configure_calibreweb |
|
|
|
|
|
|
|
# TODO |
|
|
|
# install lighttpd and configure it |
|
|
|
# install calibre web and configure it |
|
|
|
show_post_install_banner |
|
|
|
reboot_system |
|
|
|
} |
|
|
|
|
|
|
|
run_installation |
|
|
|