diff --git a/easyinstall.sh b/easyinstall.sh
index 1a95bfa8..66e4a537 100755
--- a/easyinstall.sh
+++ b/easyinstall.sh
@@ -47,6 +47,7 @@ echo -e $logo
}
VIRTUAL_DRIVER_PATH=/home/pi/images
+CFG_PATH="$HOME/.config/rascsi"
HFS_FORMAT=/usr/bin/hformat
HFDISK_BIN=/usr/bin/hfdisk
LIDO_DRIVER=~/RASCSI/lido-driver.img
@@ -141,6 +142,14 @@ function createImagesDir() {
mkdir -p $VIRTUAL_DRIVER_PATH
chmod -R 775 $VIRTUAL_DRIVER_PATH
fi
+
+ if [ -d $CFG_PATH ]; then
+ echo "The $CFG_PATH directory already exists."
+ else
+ echo "The $CFG_PATH directory does not exist; creating..."
+ mkdir -p $CFG_PATH
+ chmod -R 775 $CFG_PATH
+ fi
}
function stopOldWebInterface() {
diff --git a/src/web/file_cmds.py b/src/web/file_cmds.py
index ae37d118..f7c9cf49 100644
--- a/src/web/file_cmds.py
+++ b/src/web/file_cmds.py
@@ -11,14 +11,14 @@ from settings import *
import rascsi_interface_pb2 as proto
-def list_files(file_types):
+def list_files(file_types, dir_path):
"""
Takes a list or tuple of str file_types - e.g. ('hda', 'hds')
Returns list of lists files_list:
index 0 is str file name and index 1 is int size in bytes
"""
files_list = []
- for path, dirs, files in os.walk(base_dir):
+ for path, dirs, files in os.walk(dir_path):
# Only list selected file types
files = [f for f in files if f.lower().endswith(file_types)]
files_list.extend(
@@ -35,11 +35,11 @@ def list_files(file_types):
def list_config_files():
"""
- Returns a list of RaSCSI config files in base_dir:
+ Returns a list of RaSCSI config files in cfg_dir:
list of str files_list
"""
files_list = []
- for root, dirs, files in os.walk(base_dir):
+ for root, dirs, files in os.walk(cfg_dir):
for file in files:
if file.endswith(".json"):
files_list.append(file)
@@ -59,9 +59,9 @@ def list_images():
result = proto.PbResult()
result.ParseFromString(data)
- # Get a list of all *.properties files in base_dir
+ # Get a list of all *.properties files in cfg_dir
from pathlib import PurePath
- prop_data = list_files(PROPERTIES_SUFFIX)
+ prop_data = list_files(PROPERTIES_SUFFIX, cfg_dir)
prop_files = [PurePath(x[0]).stem for x in prop_data]
files = []
@@ -97,7 +97,7 @@ def create_new_image(file_name, file_type, size):
return {"status": result.status, "msg": result.msg}
-def delete_file(file_name):
+def delete_image(file_name):
"""
Takes str file_name
Sends a DELETE_IMAGE command to the server
@@ -114,6 +114,18 @@ def delete_file(file_name):
return {"status": result.status, "msg": result.msg}
+def delete_file(file_path):
+ """
+ Takes str file_path with the full path to the file to delete
+ Returns dict with boolean status and str msg
+ """
+ if os.path.exists(file_path):
+ os.remove(file_path)
+ return {"status": True, "msg": "File deleted"}
+ else:
+ return {"status": False, "msg": "Could not delete file"}
+
+
def unzip_file(file_name):
"""
Takes str file_name
@@ -194,7 +206,7 @@ def write_config(file_name):
Returns dict with boolean status and str msg
"""
from json import dump
- file_name = base_dir + file_name
+ file_name = cfg_dir + file_name
try:
with open(file_name, "w") as json_file:
devices = list_devices()["device_list"]
@@ -229,7 +241,7 @@ def read_config(file_name):
Returns dict with boolean status and str msg
"""
from json import load
- file_name = base_dir + file_name
+ file_name = cfg_dir + file_name
try:
with open(file_name) as json_file:
detach_all()
@@ -263,7 +275,7 @@ def write_drive_properties(file_name, conf):
"""
from json import dump
try:
- with open(base_dir + file_name, "w") as json_file:
+ with open(cfg_dir + file_name, "w") as json_file:
dump(conf, json_file, indent=4)
return {"status": True, "msg": f"Successfully wrote to file: {file_name}"}
except (IOError, ValueError, EOFError, TypeError) as e:
diff --git a/src/web/settings.py b/src/web/settings.py
index 44f38669..6197b506 100644
--- a/src/web/settings.py
+++ b/src/web/settings.py
@@ -1,6 +1,7 @@
from os import getenv, getcwd
base_dir = getenv("BASE_DIR", "/home/pi/images/")
+cfg_dir = getenv("HOME", "/home/pi/") + ".config/rascsi/"
home_dir = getcwd()
DEFAULT_CONFIG = "default.json"
diff --git a/src/web/templates/index.html b/src/web/templates/index.html
index 5f8fa3b1..0d009888 100644
--- a/src/web/templates/index.html
+++ b/src/web/templates/index.html
@@ -5,7 +5,7 @@