added hooks with order-sorting

This commit is contained in:
Leon van Kammen 2025-10-28 17:57:34 +01:00
parent ac0e1aeb0e
commit 2d558bf6f0
9 changed files with 34 additions and 52 deletions

View file

@ -71,7 +71,7 @@ hook(){
cmd=$1
shift
test -d ~/hook.d/$cmd && {
find -L ~/hook.d/$cmd/ -type f -executable -maxdepth 1 | while read hook; do
find -L ~/hook.d/$cmd/ -type f -executable -maxdepth 1 | sort -V | while read hook; do
logger " |+ hook $hook $*"
{ $hook "$@" || true; } 2>&1 | awk '{ gsub(/\/root\/\//,"",$1); $1 = sprintf("%-40s", $1)} 1' | logger
done
@ -86,6 +86,8 @@ start_hook_daemon(){
# trigger hooks when files change in /mnt
find /mnt -type d -mindepth 1 -maxdepth 1 | while read dir; do
echocolor "[$APPNAME]" "listening to inotify events in $dir"
# scan for '/mnt/experiences/creatorname/#234/ MODIFY foo.glb' e.g.
# scan for '/mnt/experiences/creatorname/#234/ MOVED_TO foo.glb' e.g.
inotifywait -r -m $dir | awk '$2 ~ /(CREATE|MODIFY|MOVED_TO|DELETE)/ { system("'$0' hook inotify_"$2" "$1""$3) }' &
done

View file

@ -0,0 +1,6 @@
#!/bin/sh
echo "$1" | grep -E 'datapackage|glb$' || exit 0 # nothing to do
dir=$(dirname $1)
cd "$dir"
echo "[v] reset log.txt"
date > log.txt

View file

@ -0,0 +1,7 @@
#!/bin/sh
echo "$1" | grep -E 'datapackage|glb$' || exit 0 # nothing to do
dir=$(dirname $1)
cd "$dir"
echo "[v] scan (new) files of model"
id="$(basename "$dir" | sed 's/\#//g')"
echo "Model.find(id).add_new_files_later()" | /usr/src/app/bin/rails console

View file

@ -1,5 +1,5 @@
#!/bin/sh
echo "$1" | grep datapackage || exit 0 # nothing to do
echo "$1" | grep -E 'datapackage|glb$' || exit 0 # nothing to do
dir=$(dirname $1)
cd "$dir"
echo "[package_experience.sh] zipping $dir.zip"

View file

@ -1,5 +1,5 @@
#!/bin/sh
echo "$1" | grep datapackage || exit 0 # nothing to do
echo "$1" | grep -E 'datapackage|glb$' || exit 0 # nothing to do
dir=$(dirname $1)
cd "$dir"
echo "[package_experience.sh] zipping $dir.zip"

View file

@ -1,5 +1,5 @@
#!/bin/sh
echo "$1" | grep datapackage || exit 0 # nothing to do
echo "$1" | grep -E 'datapackage|glb$' || exit 0 # nothing to do
dir=$(dirname $1)
cd "$dir"
echo "[package_janusxr.sh] packing janusxr.html"
@ -16,11 +16,8 @@ jml='
<janus-viewer>
<FireBoxRoom>
<Assets>
<AssetObject id="experience" src="'$glb'" ></AssetObject>
</Assets>
<Room>
<Object id="experience" locked="true" pos="0 0 0"></Object>
<Object id="experience" src="'$glb'" locked="true" pos="0 0 0"></Object>
</Room>
</FireBoxRoom>

View file

@ -15,13 +15,13 @@ begin
# Read and parse the JSON file
data = JSON.parse(File.read(filename))
logfile = File.join( File.dirname(filename), "xrfragment.txt" )
logfile = File.join( File.dirname(filename), "log.txt" )
log("✅ starting XR fragments check", logfile, true)
XRForge.log("✅ starting XR fragments check", logfile, true)
# Extract the desired field (assuming the field is named 'model_file')
thumb_file = data['image']
log("✅ thumbnail sidecar-file '#{thumb_file}' detected", logfile)
XRForge.log("✅ thumbnail sidecar-file '#{thumb_file}' detected", logfile)
# Get the base name of the thumbnail file without its extension
base_name = File.basename(thumb_file, File.extname(thumb_file))
@ -29,26 +29,26 @@ begin
model_file = nil # Initialize model_file to nil
# Loop over the list of extensions
Xrforge.model_extensions.each do |ext|
XRForge::MODEL_EXT.each do |ext|
# Construct the filename with the current extension
filename = "#{base_name}#{ext}"
# Check if the file exists
if File.exist?(filename)
log("✅ 3D file '#{filename}' detected", logfile)
XRForge.log("✅ 3D file '#{filename}' detected", logfile)
model_file = filename # Store the found filename
break # Stop the loop once a file is found
else
# Log a message for the file that was not found, but don't stop
log("⚠️ 3D file '#{filename}' not detected", logfile)
XRForge.log("⚠️ 3D file '#{filename}' not detected", logfile)
end
end
# Check if a model file was found after the loop
if model_file
log("✅ Final model file: '#{model_file}'", logfile)
XRForge.log("✅ Final model file: '#{model_file}'", logfile)
else
log("❌ No suitable 3D file found for XR Fragments-compatible experience", logfile)
XRForge.log("❌ No suitable 3D file found for XR Fragments-compatible experience", logfile)
end
# Construct the output filename
@ -58,6 +58,8 @@ begin
puts("assimp", model_file, output_file)
system("assimp", model_file, output_file)
XRForge.log(" ", logfile)
rescue Errno::ENOENT
puts "File #{filename} not found"
rescue JSON::ParserError
@ -65,6 +67,3 @@ rescue JSON::ParserError
rescue => e
puts "An error occurred: #{e.message}"
end
log("", logfile)

View file

@ -1,19 +0,0 @@
#!/bin/sh
echo "$1" | grep datapackage || exit 0 # nothing to do
dir=$(dirname $1)
cd "$dir"
test -f xrforge.yml || exit 0 # nothing to do
echo '--- # xrforge yaml v0.1
scene:
version: 1.0
xrf:
links: yes # add links from datapackage.json#/links [rezstyle fontmap / ruler]
sidecar_json: yes # add links from <experience>.json sidecar-file (https://xrfragment.org)
texture:
export: yes # extract textures from uploaded 3D file
import: yes # import uploaded texture to 3D file (when name matches)
' > xrforge.yaml

View file

@ -1,23 +1,13 @@
Module xrforge
module XRForge
model_extensions = ['.glb', '.gltf', '.blend', '.usdz', '.obj', '.dae']
def log(message, filename, reset = false)
# Empty the log file if reset is true
if reset
File.open(filename, 'w') do |file|
timestamp = Time.now.strftime('%Y-%m-%d %H:%M')
file.write("#{timestamp}\n\n")
end
end
# Create the full log entry
MODEL_EXT = ['.glb', '.gltf', '.blend', '.usdz', '.obj', '.dae']
def self.log(message, filename)
# Append the log entry to the log file
File.open(filename, 'a') do |file|
file.write("#{message}\n")
end
puts("#{message}\n")
end
end