added hooks with order-sorting
This commit is contained in:
		
							parent
							
								
									ac0e1aeb0e
								
							
						
					
					
						commit
						2d558bf6f0
					
				
					 9 changed files with 34 additions and 52 deletions
				
			
		| 
						 | 
					@ -71,7 +71,7 @@ hook(){
 | 
				
			||||||
  cmd=$1
 | 
					  cmd=$1
 | 
				
			||||||
  shift 
 | 
					  shift 
 | 
				
			||||||
  test -d ~/hook.d/$cmd && {
 | 
					  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 $*"
 | 
					      logger "    |+ hook $hook $*"
 | 
				
			||||||
      { $hook "$@" || true; } 2>&1 |  awk '{ gsub(/\/root\/\//,"",$1); $1 = sprintf("%-40s", $1)} 1' | logger
 | 
					      { $hook "$@" || true; } 2>&1 |  awk '{ gsub(/\/root\/\//,"",$1); $1 = sprintf("%-40s", $1)} 1' | logger
 | 
				
			||||||
    done
 | 
					    done
 | 
				
			||||||
| 
						 | 
					@ -86,6 +86,8 @@ start_hook_daemon(){
 | 
				
			||||||
  # trigger hooks when files change in /mnt
 | 
					  # trigger hooks when files change in /mnt
 | 
				
			||||||
  find /mnt -type d -mindepth 1 -maxdepth 1 | while read dir; do 
 | 
					  find /mnt -type d -mindepth 1 -maxdepth 1 | while read dir; do 
 | 
				
			||||||
    echocolor "[$APPNAME]" "listening to inotify events in $dir"
 | 
					    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) }' &
 | 
					    inotifywait -r -m $dir | awk '$2 ~ /(CREATE|MODIFY|MOVED_TO|DELETE)/ { system("'$0' hook inotify_"$2" "$1""$3) }' &
 | 
				
			||||||
  done
 | 
					  done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										6
									
								
								manyfold/root/hook.d/inotify_MODIFY/10-reset-log.sh
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										6
									
								
								manyfold/root/hook.d/inotify_MODIFY/10-reset-log.sh
									
										
									
									
									
										Executable 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
 | 
				
			||||||
							
								
								
									
										7
									
								
								manyfold/root/hook.d/inotify_MODIFY/1000-scan-dir.sh
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										7
									
								
								manyfold/root/hook.d/inotify_MODIFY/1000-scan-dir.sh
									
										
									
									
									
										Executable 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
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
#!/bin/sh
 | 
					#!/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)
 | 
					dir=$(dirname $1)
 | 
				
			||||||
cd "$dir"
 | 
					cd "$dir"
 | 
				
			||||||
echo "[package_experience.sh] zipping $dir.zip"
 | 
					echo "[package_experience.sh] zipping $dir.zip"
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
#!/bin/sh
 | 
					#!/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)
 | 
					dir=$(dirname $1)
 | 
				
			||||||
cd "$dir"
 | 
					cd "$dir"
 | 
				
			||||||
echo "[package_experience.sh] zipping $dir.zip"
 | 
					echo "[package_experience.sh] zipping $dir.zip"
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
#!/bin/sh
 | 
					#!/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)
 | 
					dir=$(dirname $1)
 | 
				
			||||||
cd "$dir"
 | 
					cd "$dir"
 | 
				
			||||||
echo "[package_janusxr.sh] packing janusxr.html"
 | 
					echo "[package_janusxr.sh] packing janusxr.html"
 | 
				
			||||||
| 
						 | 
					@ -16,11 +16,8 @@ jml='
 | 
				
			||||||
  <janus-viewer>
 | 
					  <janus-viewer>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <FireBoxRoom>
 | 
					    <FireBoxRoom>
 | 
				
			||||||
     <Assets>
 | 
					 | 
				
			||||||
        <AssetObject id="experience" src="'$glb'" ></AssetObject> 
 | 
					 | 
				
			||||||
     </Assets>
 | 
					 | 
				
			||||||
     <Room>
 | 
					     <Room>
 | 
				
			||||||
       <Object id="experience" locked="true" pos="0 0 0"></Object> 
 | 
					       <Object id="experience" src="'$glb'" locked="true" pos="0 0 0"></Object> 
 | 
				
			||||||
     </Room>
 | 
					     </Room>
 | 
				
			||||||
    </FireBoxRoom>
 | 
					    </FireBoxRoom>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,13 +15,13 @@ begin
 | 
				
			||||||
  # Read and parse the JSON file
 | 
					  # Read and parse the JSON file
 | 
				
			||||||
  data = JSON.parse(File.read(filename))
 | 
					  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')
 | 
					  # Extract the desired field (assuming the field is named 'model_file')
 | 
				
			||||||
  thumb_file = data['image']
 | 
					  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
 | 
					  # Get the base name of the thumbnail file without its extension
 | 
				
			||||||
  base_name = File.basename(thumb_file, File.extname(thumb_file))
 | 
					  base_name = File.basename(thumb_file, File.extname(thumb_file))
 | 
				
			||||||
| 
						 | 
					@ -29,26 +29,26 @@ begin
 | 
				
			||||||
  model_file = nil # Initialize model_file to nil
 | 
					  model_file = nil # Initialize model_file to nil
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  # Loop over the list of extensions
 | 
					  # 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
 | 
					    # Construct the filename with the current extension
 | 
				
			||||||
    filename = "#{base_name}#{ext}"
 | 
					    filename = "#{base_name}#{ext}"
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
    # Check if the file exists
 | 
					    # Check if the file exists
 | 
				
			||||||
    if File.exist?(filename)
 | 
					    if File.exist?(filename)
 | 
				
			||||||
      log("✅ 3D file '#{filename}' detected", logfile)
 | 
					      XRForge.log("✅ 3D file '#{filename}' detected", logfile)
 | 
				
			||||||
      model_file = filename # Store the found filename
 | 
					      model_file = filename # Store the found filename
 | 
				
			||||||
      break # Stop the loop once a file is found
 | 
					      break # Stop the loop once a file is found
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      # Log a message for the file that was not found, but don't stop
 | 
					      # 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
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  # Check if a model file was found after the loop
 | 
					  # Check if a model file was found after the loop
 | 
				
			||||||
  if model_file
 | 
					  if model_file
 | 
				
			||||||
    log("✅ Final model file: '#{model_file}'", logfile)
 | 
					    XRForge.log("✅ Final model file: '#{model_file}'", logfile)
 | 
				
			||||||
  else
 | 
					  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
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # Construct the output filename
 | 
					  # Construct the output filename
 | 
				
			||||||
| 
						 | 
					@ -58,6 +58,8 @@ begin
 | 
				
			||||||
  puts("assimp", model_file, output_file)
 | 
					  puts("assimp", model_file, output_file)
 | 
				
			||||||
  system("assimp", model_file, output_file)
 | 
					  system("assimp", model_file, output_file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  XRForge.log(" ", logfile)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
rescue Errno::ENOENT
 | 
					rescue Errno::ENOENT
 | 
				
			||||||
  puts "File #{filename} not found"
 | 
					  puts "File #{filename} not found"
 | 
				
			||||||
rescue JSON::ParserError
 | 
					rescue JSON::ParserError
 | 
				
			||||||
| 
						 | 
					@ -65,6 +67,3 @@ rescue JSON::ParserError
 | 
				
			||||||
rescue => e
 | 
					rescue => e
 | 
				
			||||||
  puts "An error occurred: #{e.message}"
 | 
					  puts "An error occurred: #{e.message}"
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
log("", logfile)
 | 
					 | 
				
			||||||
| 
						 | 
					@ -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
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,23 +1,13 @@
 | 
				
			||||||
Module xrforge
 | 
					module XRForge
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  model_extensions = ['.glb', '.gltf', '.blend', '.usdz', '.obj', '.dae']
 | 
					  MODEL_EXT = ['.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
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def self.log(message, filename)
 | 
				
			||||||
    # Append the log entry to the log file
 | 
					    # Append the log entry to the log file
 | 
				
			||||||
    File.open(filename, 'a') do |file|
 | 
					    File.open(filename, 'a') do |file|
 | 
				
			||||||
      file.write("#{message}\n")
 | 
					      file.write("#{message}\n")
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
    puts("#{message}\n")
 | 
					    puts("#{message}\n")
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue