#!/usr/bin/env bash # BSD 3-Clause License # Author @sonique6784 # Copyright (c) 2020, sonique6784 function showRaSCSILogo(){ logo="""     .~~.   .~~.\n   '. \ ' ' / .'\n    .╔═══════╗.\n   : ║|¯¯¯¯¯|║ :\n  ~ (║|_____|║) ~\n ( : ║ .  __ ║ : )\n  ~ .╚╦═════╦╝. ~\n   (  ¯¯¯¯¯¯¯  ) RaSCSI Assistant\n    '~ .~~~. ~'\n        '~'\n """ echo -e $logo } function showMacNetworkWired(){ logo="""                               .-~-.-~~~-.~-.\n  ╔═══════╗                  .(              )\n  ║|¯¯¯¯¯|║                 /               \`.\n  ║|_____|║>--------------<~               .   )\n  ║ .  __ ║                 (              :'-'\n  ╚╦═════╦╝                  ~-.________.:'\n   ¯¯¯¯¯¯¯\n """ echo -e $logo } function showMacNetworkWireless(){ logo="""                               .-~-.-~~~-.~-.\n  ╔═══════╗        .(       .(              )\n  ║|¯¯¯¯¯|║  .(  .(        /               \`.\n  ║|_____|║ .o    o       ~               .   )\n  ║ .  __ ║  '(  '(        (              :'-'\n  ╚╦═════╦╝        '(       ~-.________.:'\n   ¯¯¯¯¯¯¯\n """ echo -e $logo } USER=$(whoami) BASE=$(dirname "$(readlink -f "${0}")") VIRTUAL_DRIVER_PATH="$HOME/images" CFG_PATH="$HOME/.config/rascsi" WEB_INSTALL_PATH="$BASE/src/web" SYSTEMD_PATH="/etc/systemd/system" HFS_FORMAT=/usr/bin/hformat HFDISK_BIN=/usr/bin/hfdisk LIDO_DRIVER=$BASE/lido-driver.img GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) GIT_REMOTE=${GIT_REMOTE:-origin} 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() { echo "Input your password to allow this script to make the above changes." sudo -v } # install all dependency packages for RaSCSI Service function installPackages() { sudo apt-get update && sudo apt-get install git libspdlog-dev libpcap-dev genisoimage python3 python3-venv nginx libpcap-dev protobuf-compiler bridge-utils python3-dev libev-dev libevdev2 -y > /etc/sudoers' else echo "The sudoers file is already modified for rascsi-web." fi sudo systemctl reload nginx || true } # updates configuration files and installs packages needed for the OLED screen script function installRaScsiScreen() { echo "IMPORTANT: This configuration requires a OLED screen to be installed onto your RaSCSI board." echo "See wiki for more information: https://github.com/akuker/RASCSI/wiki/OLED-Status-Display-(Optional)" echo "" echo "Choose screen rotation:" echo " 1) 0 degrees" echo " 2) 180 degrees (default)" read REPLY if [ "$REPLY" == "1" ]; then echo "Proceeding with 0 degrees rotation." ROTATION="0" else echo "Proceeding with 180 degrees rotation." ROTATION="180" fi echo "" echo "Choose screen resolution:" echo " 1) 128x32 pixels (default)" echo " 2) 128x64 pixels" read REPLY if [ "$REPLY" == "2" ]; then echo "Proceeding with 128x64 pixel resolution." SCREEN_HEIGHT="64" else echo "Proceeding with 128x32 pixel resolution." SCREEN_HEIGHT="32" fi stopRaScsiScreen updateRaScsiGit sudo apt-get update && sudo apt-get install python3-dev python3-pip python3-venv libjpeg-dev libpng-dev libopenjp2-7-dev i2c-tools raspi-config -y /dev/null; echo $?) if [ "$APACHE_STATUS" -eq 0 ] ; then echo "Stopping old Apache2 RaSCSI Web..." sudo systemctl disable apache2 sudo systemctl stop apache2 fi } # Checks for upstream changes to the git repo and fast-forwards changes if needed function updateRaScsiGit() { cd "$BASE" || exit 1 stashed=0 if [[ $(git diff --stat) != '' ]]; then echo "There are local changes to the RaSCSI code; we will stash and reapply them." git -c user.name="${GIT_COMMITTER_NAME-rascsi}" -c user.email="${GIT_COMMITTER_EMAIL-rascsi@rascsi.com}" stash stashed=1 fi if [[ `git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD)"` != "" ]]; then echo "Updating checked out git branch $GIT_REMOTE/$GIT_BRANCH" git pull --ff-only else echo "Detected a local git working branch; skipping the remote update step." fi if [ $stashed -eq 1 ]; then echo "Reapplying local changes..." git stash apply fi } # Takes a backup copy of the rascsi.service file if it exists function backupRaScsiService() { if [ -f "$SYSTEMD_PATH/rascsi.service" ]; then sudo mv "$SYSTEMD_PATH/rascsi.service" "$SYSTEMD_PATH/rascsi.service.old" SYSTEMD_BACKUP=true echo "Existing version of rascsi.service detected; Backing up to rascsi.service.old" else SYSTEMD_BACKUP=false fi } # Modifies and installs the rascsi service function enableRaScsiService() { sudo sed -i "s@^ExecStart.*@& -F $VIRTUAL_DRIVER_PATH@" "$SYSTEMD_PATH/rascsi.service" echo "Configured rascsi.service to use $VIRTUAL_DRIVER_PATH as default image dir." sudo systemctl daemon-reload sudo systemctl restart rsyslog sudo systemctl enable rascsi # optional - start rascsi at boot sudo systemctl start rascsi } # Modifies and installs the rascsi-web service function installWebInterfaceService() { echo "Installing the rascsi-web.service configuration..." sudo cp -f "$BASE/src/web/service-infra/rascsi-web.service" "$SYSTEMD_PATH/rascsi-web.service" sudo sed -i /^ExecStart=/d "$SYSTEMD_PATH/rascsi-web.service" sudo sed -i "8 i ExecStart=$WEB_INSTALL_PATH/start.sh" "$SYSTEMD_PATH/rascsi-web.service" sudo systemctl daemon-reload sudo systemctl enable rascsi-web sudo systemctl start rascsi-web } # Stops the rascsi service if it is running function stopRaScsi() { if [ -f "$SYSTEMD_PATH/rascsi.service" ]; then sudo systemctl stop rascsi.service fi } # Stops the rascsi-web service if it is running function stopRaScsiWeb() { if [ -f "$SYSTEMD_PATH/rascsi-web.service" ]; then sudo systemctl stop rascsi-web.service fi } # Stops the monitor_rascsi service if it is running function stopRaScsiScreen() { if [ -f "$SYSTEMD_PATH/monitor_rascsi.service" ]; then sudo systemctl stop monitor_rascsi.service fi } # Stops the macproxy service if it is running function stopMacproxy() { if [ -f "$SYSTEMD_PATH/macproxy.service" ]; then sudo systemctl stop macproxy.service fi } # Starts the monitor_rascsi service if installed function startRaScsiScreen() { if [ -f "$SYSTEMD_PATH/monitor_rascsi.service" ]; then sudo systemctl start monitor_rascsi.service showRaScsiScreenStatus fi } # Starts the macproxy service if installed function startMacproxy() { if [ -f "$SYSTEMD_PATH/macproxy.service" ]; then sudo systemctl start macproxy.service showMacproxyStatus fi } # Shows status for the rascsi service function showRaScsiStatus() { systemctl status rascsi | tee } # Shows status for the rascsi-web service function showRaScsiWebStatus() { systemctl status rascsi-web | tee } # Shows status for the monitor_rascsi service function showRaScsiScreenStatus() { systemctl status monitor_rascsi | tee } # Shows status for the macproxy service function showMacproxyStatus() { systemctl status macproxy | tee } # Creates a drive image file with specific parameters function createDrive600MB() { createDrive 600 "HD600" } # Creates a drive image file and prompts for parameters function createDriveCustom() { driveSize=-1 until [ $driveSize -ge "10" ] && [ $driveSize -le "4000" ]; do echo "What drive size would you like (in MB) (10-4000)" read driveSize echo "How would you like to name that drive?" read driveName done createDrive "$driveSize" "$driveName" } # Creates an HFS file system function formatDrive() { diskPath="$1" volumeName="$2" if [ ! -x $HFS_FORMAT ]; then # Install hfsutils to have hformat to format HFS sudo apt-get install hfsutils --assume-yes > /etc/dhcpcd.conf' echo "Modified /etc/dhcpcd.conf" # default config file is made for eth0, this will set the right net interface sudo bash -c 'sed s/eth0/'"$LAN_INTERFACE"'/g '"$BASE"'/src/raspberrypi/os_integration/rascsi_bridge > /etc/network/interfaces.d/rascsi_bridge' echo "Modified /etc/network/interfaces.d/rascsi_bridge" echo "Configuration completed!" echo "Please make sure you attach a DaynaPORT network adapter to your RaSCSI configuration." echo "Either use the Web UI, or do this on the command line (assuming SCSI ID 6):" echo "rasctl -i 6 -c attach -t scdp -f $LAN_INTERFACE" echo "" echo "We need to reboot your Pi" echo "Press Enter to reboot or CTRL-C to exit" read echo "Rebooting..." sleep 3 sudo reboot } # Modifies system configurations for a wireless network bridge with NAT function setupWirelessNetworking() { NETWORK="10.10.20" IP=$NETWORK.2 # Macintosh or Device IP NETWORK_MASK="255.255.255.0" CIDR="24" ROUTER_IP=$NETWORK.1 ROUTING_ADDRESS=$NETWORK.0/$CIDR WLAN_INTERFACE="wlan0" echo "$WLAN_INTERFACE will be configured for network forwarding with static IP assignment." echo "Configure your Macintosh or other device with the following:" echo "IP Address (static): $IP" echo "Router Address: $ROUTER_IP" echo "Subnet Mask: $NETWORK_MASK" echo "DNS Server: Any public DNS server" echo "" echo "Do you want to proceed with network configuration using the default settings? Y/n" read REPLY if [ "$REPLY" == "N" ] || [ "$REPLY" == "n" ]; then echo "Available wireless interfaces on this system:" echo `ip -o addr show scope link | awk '{split($0, a); print $2}' | grep wlan` echo "Please type the wireless interface you want to use and press Enter:" read -r WLAN_INTERFACE echo "Base IP address (ex. 10.10.20):" read -r NETWORK echo "CIDR for Subnet Mask (ex. '24' for 255.255.255.0):" read -r CIDR ROUTER_IP=$NETWORK.1 ROUTING_ADDRESS=$NETWORK.0/$CIDR fi if [ "$(grep -c "^net.ipv4.ip_forward=1" /etc/sysctl.conf)" -ge 1 ]; then echo "WARNING: Network forwarding may already have been configured. Proceeding will overwrite the configuration." echo "Press enter to continue or CTRL-C to exit" read REPLY else sudo bash -c 'echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf' echo "Modified /etc/sysctl.conf" fi # Check if iptables is installed if [ `apt-cache policy iptables | grep Installed | grep -c "(none)"` -eq 0 ]; then echo "iptables is already installed" else sudo apt-get install iptables --assume-yes > ./config/AppleVolumes.default.tmpl echo "ATALKD_RUN=yes" >> ./config/netatalk.conf echo "\"RaSCSI-Pi\" -transall -uamlist uams_guest.so,uams_clrtxt.so,uams_dhx.so -defaultvol /etc/netatalk/AppleVolumes.default -systemvol /etc/netatalk/AppleVolumes.system -nosavepassword -nouservol -guestname \"nobody\" -setuplog \"default log_maxdebug /var/log/afpd.log\"" >> ./config/afpd.conf.tmpl ( sudo apt-get update && sudo apt-get install libssl-dev libdb-dev libcups2-dev autotools-dev automake libtool --assume-yes )