#!/usr/bin/env bash # BSD 3-Clause License # Author @sonique6784 # Copyright (c) 2020, sonique6784 # Copyright (c) 2021-2026, Daniel Markstedt function showPiSCSILogo(){ logo="""     .~~.   .~~.\n   '. \ ' ' / .'\n    .╔═══════╗.\n   : ║|¯¯¯¯¯|║ :\n  ~ (║|_____|║) ~\n ( : ║ .  __ ║ : )\n  ~ .╚╦═════╦╝. ~\n   (  ¯¯¯¯¯¯¯  ) PiSCSI Assistant\n    '~ .~~~. ~'\n        '~'\n """ echo -e $logo } USER=$(whoami) BASE=$(dirname "$(readlink -f "${0}")") PISCSI_STATEDIR="/var/lib/piscsi" VIRTUAL_DRIVER_PATH="$PISCSI_STATEDIR/images" CFG_PATH="$PISCSI_STATEDIR/config" DRIVER_PATH="$PISCSI_STATEDIR/data/mac-hard-disk-drivers" SYSTEMD_PATH="/usr/lib/systemd/system" HFDISK_BIN=/usr/bin/hfdisk TOKEN="" SECRET_FILE="$CFG_PATH/secret" FILE_SHARE_PATH="$PISCSI_STATEDIR/shared" FILE_SHARE_NAME="Pi File Server" set -e # checks to run before entering the script main menu function initialChecks() { if [ "root" == "$USER" ]; then echo "Do not run this script as $USER or with 'sudo'." exit 1 fi } # checks that the current user has sudoers privileges function sudoCheck() { if [[ $HEADLESS ]]; then echo "Skipping password check in headless mode" return 0 fi echo "Input your password to allow this script to make the above changes." sudo -v } # update apt repositories function updateAptSources() { if [[ $SKIP_PACKAGES ]]; then echo "Skipping package update" return 0 fi sudo apt-get update } # Offers the choice of enabling token-based authentication for PiSCSI, or disables it if enabled function configureTokenAuth() { if [[ -f $SECRET_FILE ]]; then sudo rm "$SECRET_FILE" echo "PiSCSI token file $SECRET_FILE already exists. Do you want to disable authentication? (y/N)" read REPLY if [[ $REPLY =~ ^[Yy]$ ]]; then sudo sed -i 's@-P '"$SECRET_FILE"'@@' "$SYSTEMD_PATH/piscsi.service" return fi fi echo -n "Enter the token password for protecting PiSCSI: " read -r TOKEN printf '%s\n' "$TOKEN" | sudo tee "$SECRET_FILE" > /dev/null # Make the secret file owned and only readable by root sudo chown root:root "$SECRET_FILE" sudo chmod 600 "$SECRET_FILE" sudo sed -i "s@^ExecStart.*@& -P $SECRET_FILE@" "$SYSTEMD_PATH/piscsi.service" sudo systemctl daemon-reload sudo systemctl start piscsi.service echo "" echo "Configured PiSCSI to use $SECRET_FILE for authentication. This file is readable by root only." echo "Make note of your password: you will need it to use scsictl and other PiSCSI clients." echo "If you have PiSCSI clients installed, please re-run the installation scripts, or update the systemd config manually." } # Stops a service if it is running function stopService() { if [[ -f "$SYSTEMD_PATH/$1.service" ]]; then SERVICE_RUNNING=0 sudo systemctl is-active --quiet "$1.service" >/dev/null 2>&1 || SERVICE_RUNNING=$? if [[ $SERVICE_RUNNING -eq 0 ]]; then sudo systemctl stop "$1.service" fi fi } # Starts the macproxy service if installed function startMacproxy() { if [ -f "$SYSTEMD_PATH/macproxy.service" ]; then sudo systemctl start macproxy.service showServiceStatus "macproxy" fi } # Shows status for a service function showServiceStatus() { systemctl status "$1.service" | tee } # Clone, compile and install 'hfdisk', partition tool function installHfdisk() { HFDISK_VERSION="2022.11" if [ ! -x "$HFDISK_BIN" ]; then cd "$BASE" || exit 1 wget -O "hfdisk-$HFDISK_VERSION.tar.gz" "https://github.com/rdmark/hfdisk/archive/refs/tags/$HFDISK_VERSION.tar.gz" /dev/null echo "Added share section for $share_name to afp.conf" } # Downloads, compiles, and installs Macproxy (web proxy) function installMacproxy { PORT=5001 echo "Macproxy Classic is a Web Proxy for all vintage Web Browsers -- not only for Macs!" echo "" echo "By default, Macproxy Classic listens to port $PORT, but you can choose any other available port." echo -n "Enter a port number 1024 - 65535, or press Enter to use the default port: " read -r CHOICE if [[ $CHOICE -ge "1024" ]] && [[ $CHOICE -le "65535" ]]; then PORT=$CHOICE else echo "Using the default port $PORT" fi if [[ $SKIP_PACKAGES ]]; then echo "Skipping package installation" else sudo apt-get install python3 python3-venv --assume-yes --no-install-recommends /dev/null || true wget -O vsftpd.wbm.tgz "https://github.com/rdmark/vsftpd-webmin/releases/download/$WEBMIN_VSFTPD_MODULE_VERSION/vsftpd-$WEBMIN_VSFTPD_MODULE_VERSION.wbm.gz"