Make rascsi, rascsi-web and easyinstall.sh portable (#426)

* Make install script portable

* Modify rascsi-web service to accommodate portability

* Remove initialChecks call

* Introduce USER global variable

* Make the web app portable

* Make netatalk installation script portable

* Cleanup

* Cleanup

* Configure default image dir in rascsi.service
This commit is contained in:
Daniel Markstedt 2021-11-08 18:33:33 -08:00 committed by GitHub
parent b54977daa6
commit 988a2ffe1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 22 deletions

View File

@ -46,7 +46,8 @@ logo="""
echo -e $logo
}
BASE="$HOME/RASCSI"
USER=$(whoami)
BASE=$(dirname "$(readlink -f "${0}")")
VIRTUAL_DRIVER_PATH="$HOME/images"
CFG_PATH="$HOME/.config/rascsi"
WEBINSTDIR="$BASE/src/web"
@ -58,20 +59,6 @@ GIT_REMOTE=${GIT_REMOTE:-origin}
set -e
function initialChecks() {
currentUser=$(whoami)
if [ "pi" != "$currentUser" ]; then
echo "You must use 'pi' user (current: $currentUser)"
exit 1
fi
if [ ! -d "$BASE" ]; then
echo "You must checkout RASCSI repo into $BASE"
echo "$ git clone git@github.com:akuker/RASCSI.git"
exit 2
fi
}
# 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 </dev/null
@ -94,6 +81,9 @@ function installRaScsi() {
( make clean && make all CONNECT_TYPE="${CONNECT_TYPE-FULLSPEC}" && sudo make install CONNECT_TYPE="${CONNECT_TYPE-FULLSPEC}" ) </dev/null
sudo sed -i "s@^ExecStart.*@& -F $VIRTUAL_DRIVER_PATH@" /etc/systemd/system/rascsi.service
echo "Configured rascsi.service to use $VIRTUAL_DRIVER_PATH as default image dir."
if [[ `sudo grep -c "rascsi" /etc/sudoers` -eq 0 ]]; then
sudo bash -c 'echo "
# Allow the web server to restart the rascsi service
@ -126,12 +116,14 @@ function installRaScsiWebInterface() {
sudo cp -f "$BASE/src/web/service-infra/nginx-default.conf" /etc/nginx/sites-available/default
sudo cp -f "$BASE/src/web/service-infra/502.html" /var/www/html/502.html
sudo usermod -a -G pi www-data
sudo usermod -a -G $USER www-data
sudo systemctl reload nginx || true
echo "Installing the rascsi-web.service configuration..."
sudo cp -f "$BASE/src/web/service-infra/rascsi-web.service" /etc/systemd/system/rascsi-web.service
sudo sed -i /^ExecStart=/d /etc/systemd/system/rascsi-web.service
sudo sed -i "8 i ExecStart=$WEBINSTDIR/start.sh" /etc/systemd/system/rascsi-web.service
sudo systemctl daemon-reload
sudo systemctl enable rascsi-web
@ -561,7 +553,7 @@ function installNetatalk() {
cd "netatalk-classic-$NETATALK_VERSION" || exit 1
sed -i /^~/d ./config/AppleVolumes.default.tmpl
echo "/home/pi/afpshare \"Pi File Server\" adouble:v1 volcharset:ASCII" >> ./config/AppleVolumes.default.tmpl
echo "$AFP_SHARE_PATH \"Pi File Server\" adouble:v1 volcharset:ASCII" >> ./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
@ -749,7 +741,6 @@ while [ "$1" != "" ]; do
done
showRaSCSILogo
initialChecks
if [ -z "${RUN_CHOICE}" ]; then # RUN_CHOICE is unset, show menu
showMenu

View File

@ -4,12 +4,11 @@ Constant definitions used by other modules
from os import getenv, getcwd
# TODO: Make HOME_DIR portable when running rascsi-web
# as a service, since the HOME env variable doesn't get set then.
HOME_DIR = getenv("HOME", "/home/pi")
WEB_DIR = getcwd()
# There may be a more elegant way to get the HOME dir of the user that installed RaSCSI
HOME_DIR = "/".join(WEB_DIR.split("/")[0:3])
CFG_DIR = f"{HOME_DIR}/.config/rascsi/"
AFP_DIR = f"{HOME_DIR}/afpshare"
WEB_DIR = getcwd()
MAX_FILE_SIZE = getenv("MAX_FILE_SIZE", str(1024 * 1024 * 1024 * 4)) # 4gb