diff --git a/.gitignore b/.gitignore index e17ba71f..b2368f8d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ core __pycache__ src/web/current src/oled_monitor/current +src/raspberrypi/hfdisk/ diff --git a/easyinstall.sh b/easyinstall.sh index c88bed29..d9cc1505 100755 --- a/easyinstall.sh +++ b/easyinstall.sh @@ -25,6 +25,7 @@ HFS_FORMAT=/usr/bin/hformat HFDISK_BIN=/usr/bin/hfdisk LIDO_DRIVER=~/RASCSI/lido-driver.img GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) +GIT_REMOTE=${GIT_REMOTE:-origin} function initialChecks() { currentUser=$(whoami) @@ -41,7 +42,7 @@ function initialChecks() { } function installPackages() { - sudo apt-get update && sudo apt install git libspdlog-dev libpcap-dev genisoimage python3 python3-venv nginx libpcap-dev protobuf-compiler bridge-utils -y + sudo apt-get update && sudo apt install git libspdlog-dev libpcap-dev genisoimage python3 python3-venv nginx libpcap-dev protobuf-compiler bridge-utils python3-dev libev-dev libevdev2 -y } # install all dependency packages for RaSCSI Service @@ -102,12 +103,22 @@ function installRaScsiWebInterface() { } function updateRaScsiGit() { - echo "Updating checked out branch $GIT_BRANCH" + echo "Updating checked out branch $GIT_REMOTE/$GIT_BRANCH" cd ~/RASCSI - git fetch origin - git stash - git rebase origin/$GIT_BRANCH - git stash apply + stashed=0 + if [[ $(git diff --stat) != '' ]]; then + echo 'There are local changes, we will stash and reapply them.' + git stash + stashed=1 + fi + + git fetch $GIT_REMOTE + git rebase $GIT_REMOTE/$GIT_BRANCH + + if [ $stashed -eq 1 ]; then + echo "Reapplying local changes..." + git stash apply + fi } function updateRaScsi() { @@ -128,6 +139,7 @@ function updateRaScsiWebInterface() { updateRaScsiGit sudo cp -f ~/RASCSI/src/web/service-infra/nginx-default.conf /etc/nginx/sites-available/default sudo cp -f ~/RASCSI/src/web/service-infra/502.html /var/www/html/502.html + echo "Restarting rascsi-web services..." sudo systemctl restart rascsi-web sudo systemctl restart nginx } @@ -150,7 +162,7 @@ function createDriveCustom() { read driveName done - createDrive $driveSize "$driveName" + createDrive "$driveSize" "$driveName" } function formatDrive() { @@ -167,17 +179,17 @@ function formatDrive() { git clone git://www.codesrc.com/git/hfdisk.git cd hfdisk make - + sudo cp hfdisk /usr/bin/hfdisk fi # Inject hfdisk commands to create Drive with correct partitions - (echo i; echo ; echo C; echo ; echo 32; echo "Driver_Partition"; echo "Apple_Driver"; echo C; echo ; echo ; echo "${volumeName}"; echo "Apple_HFS"; echo w; echo y; echo p;) | $HFDISK_BIN "$diskPath" + (echo i; echo ; echo C; echo ; echo 32; echo "Driver_Partition"; echo "Apple_Driver"; echo C; echo ; echo ; echo "${volumeName}"; echo "Apple_HFS"; echo w; echo y; echo p;) | $HFDISK_BIN "$diskPath" partitionOk=$? if [ $partitionOk -eq 0 ]; then if [ ! -f $LIDO_DRIVER ];then - echo "Lido driver couldn't be found. Make sure RASCSI is up-to-date with git pull" + echo "Lido driver couldn't be found. Make sure RaSCSI is up-to-date with git pull" return 1 fi @@ -217,7 +229,7 @@ function createDrive() { driveName=$2 mkdir -p $VIRTUAL_DRIVER_PATH drivePath="${VIRTUAL_DRIVER_PATH}/${driveSize}MB.hda" - + if [ ! -f $drivePath ]; then echo "Creating a ${driveSize}MB Drive" truncate --size ${driveSize}m $drivePath @@ -230,6 +242,75 @@ function createDrive() { fi } +function runChoice() { + case $1 in + 0) + echo "Installing RaSCSI Service + Web interface" + installRaScsi + installRaScsiWebInterface + createDrive600MB + showRaScsiStatus + echo "Installing RaSCSI Service + Web interface - Complete!" + ;; + 1) + echo "Installing RaSCSI Service" + installRaScsi + showRaScsiStatus + echo "Installing RaSCSI Service - Complete!" + ;; + 2) + echo "Installing RaSCSI Web interface" + installRaScsiWebInterface + echo "Installing RaSCSI Web interface - Complete!" + ;; + 3) + echo "Updating RaSCSI Service + Web interface" + updateRaScsi + updateRaScsiWebInterface + showRaScsiStatus + echo "Updating RaSCSI Service + Web interface - Complete!" + ;; + 4) + echo "Updating RaSCSI Service" + updateRaScsi + showRaScsiStatus + echo "Updating RaSCSI Service - Complete!" + ;; + 5) + echo "Updating RaSCSI Web interface" + updateRaScsiWebInterface + echo "Updating RaSCSI Web interface - Complete!" + ;; + 6) + echo "Creating a 600MB drive" + createDrive600MB + echo "Creating a 600MB drive - Complete!" + ;; + 7) + echo "Creating a custom drive" + createDriveCustom + echo "Creating a custom drive - Complete!" + ;; + -h|--help|h|help) + showMenu + ;; + *) + echo "${1} is not a valid option, exiting..." + exit 1 + esac +} + +function readChoice() { + choice=-1 + + until [ $choice -ge "0" ] && [ $choice -le "7" ]; do + echo -n "Enter your choice (0-7) or CTRL-C to exit: " + read -r choice + done + + runChoice "$choice" +} + function showMenu() { echo "" echo "Choose among the following options:" @@ -244,60 +325,14 @@ function showMenu() { echo "CREATE EMPTY DRIVE" echo " 6) 600MB drive (recommended)" echo " 7) custom drive size (up to 4000MB)" - - - choice=-1 - - until [ $choice -ge "0" ] && [ $choice -le "7" ]; do - echo -n "Enter your choice (0-7) or CTRL-C to exit: " - read -r choice - done - - - case $choice in - 0) - echo "Installing RaSCSI Service + Web interface" - installRaScsi - installRaScsiWebInterface - createDrive600MB - showRaScsiStatus - ;; - 1) - echo "Installing RaSCSI Service" - installRaScsi - showRaScsiStatus - ;; - 2) - echo "Installing RaSCSI Web interface" - installRaScsiWebInterface - ;; - 3) - echo "Updating RaSCSI Service + Web interface" - updateRaScsi - updateRaScsiWebInterface - showRaScsiStatus - ;; - 4) - echo "Updating RaSCSI Service" - updateRaScsi - showRaScsiStatus - ;; - 5) - echo "Updating RaSCSI Web interface" - updateRaScsiWebInterface - ;; - 6) - echo "Creating a 600MB drive" - createDrive600MB - ;; - 7) - echo "Creating a custom drive" - createDriveCustom - ;; - esac } showRaSCSILogo initialChecks -showMenu +if [ -z "${1}" ]; then # $1 is unset, show menu + showMenu + readChoice +else + runChoice "$1" +fi diff --git a/src/web/file_cmds.py b/src/web/file_cmds.py index 7ca5d19e..9ff3c8f1 100644 --- a/src/web/file_cmds.py +++ b/src/web/file_cmds.py @@ -6,8 +6,8 @@ import time from ractl_cmds import attach_image from settings import * -valid_file_types = ["*.hda", "*.iso", "*.cdr"] -valid_file_types = r"|".join([fnmatch.translate(x) for x in valid_file_types]) +valid_file_suffix = ["*.hda", "*.hdn", "*.hdi", "*.nhd", "*.hdf", "*.hds", "*.iso", "*.cdr", "*.zip"] +valid_file_types = r"|".join([fnmatch.translate(x) for x in valid_file_suffix]) def create_new_image(file_name, type, size): diff --git a/src/web/ractl_cmds.py b/src/web/ractl_cmds.py index fbc9cef5..de288520 100644 --- a/src/web/ractl_cmds.py +++ b/src/web/ractl_cmds.py @@ -1,12 +1,12 @@ import fnmatch -import os import subprocess import re from settings import * -valid_file_types = ["*.hda", "*.iso", "*.cdr", "*.zip"] -valid_file_types = r"|".join([fnmatch.translate(x) for x in valid_file_types]) + +valid_file_suffix = ["*.hda", "*.hdn", "*.hdi", "*.nhd", "*.hdf", "*.hds", "*.iso", "*.cdr", "*.zip"] +valid_file_types = r"|".join([fnmatch.translate(x) for x in valid_file_suffix]) # List of SCSI ID's you'd like to exclude - eg if you are on a Mac, the System is usually 7 EXCLUDE_SCSI_IDS = [7] diff --git a/src/web/requirements.txt b/src/web/requirements.txt index ab184b10..5983c740 100644 --- a/src/web/requirements.txt +++ b/src/web/requirements.txt @@ -1,5 +1,6 @@ +bjoern==3.1.0 click==7.1.2 -Flask==2.0.0 +Flask==2.0.1 itsdangerous==2.0.0 Jinja2==3.0.0 machfs==1.2.4 @@ -7,6 +8,5 @@ macresources==1.2 MarkupSafe==2.0.0 rsrcfork==1.8.0 waitress==1.4.4 -Werkzeug==2.0.0 zope.event==4.5.0 zope.interface==5.1.2 diff --git a/src/web/start.sh b/src/web/start.sh index ee0b1b37..de50c04a 100755 --- a/src/web/start.sh +++ b/src/web/start.sh @@ -37,6 +37,7 @@ if ! test -e venv; then echo "Activating venv" source venv/bin/activate echo "Installing requirements.txt" + pip install wheel pip install -r requirements.txt git rev-parse HEAD > current fi @@ -55,4 +56,4 @@ else fi echo "Starting web server..." -python3 web.py \ No newline at end of file +python3 web.py diff --git a/src/web/templates/index.html b/src/web/templates/index.html index d7bbccdd..33130f01 100644 --- a/src/web/templates/index.html +++ b/src/web/templates/index.html @@ -153,7 +153,7 @@
- |