Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env fish
- # ==================== AIRWAVE DLL BATCH LINKER ====================
- # by an airwave user
- #
- # READ THIS INTRODUCTION BEFORE ATTEMPTING TO USE IT
- #
- # ==================== HOW TO USE IT ===============================
- # This is a fish shell function. Put this file in your function
- # directory. If you don't know where it is, you're probably not using
- # the fish shell. You can read this script and port it to any other
- # shell if you want. That's the spirit of free software. [g]
- #
- # Next, cd to the directory that contains the DLL files of the Windows
- # plugins and run the command. All the *.dll files in the current
- # directory will be found and linked RECURSIVELY. Yes, recursively, so
- # make sure you're happy with the directory location and structure
- # before you run this.
- #
- # Example:
- # $ cd /some/directory/with/a/truckload/of/plugins
- # $ airblast
- #
- # After you run the command, a temporary file will be opened in a text
- # editor. I use Vim, but it is easy to edit this script and change it
- # to another editor of your preference. So this is your chance to edit
- # the names of the plugins. You can change them or not. Your call.
- # The NAMES ARE ON THE FAR LEFT OF EACH LINE, right BEFORE THE FIRST
- # FORWARD SLASH. Be careful not to delete the forward slash. It is a
- # delimiter and the entire operation will break if you delete the
- # forward slash. Also, don't use the forward slash in the name of any
- # plugin. If you do, it will become the first forward slash of the
- # line, in a rather expected and inconvenient place, and the script
- # will certainly make some bizarre mistake.
- # Everything after the first forward slash of the line is the path to
- # the .dll file of the actual plugin. DON'T CHANGE ANY OF THAT.
- # When you finish editing, save the file and close it. When Vim exits,
- # the script will continue its job and will create all the necessary
- # Airwave bridge links in one fell swoop.
- #
- # The location where the plugin links will be created is hard wired.
- # They will be created in the following directory:
- # /usr/lib/vst/airwave/
- # Besides, you MUST have at least one *.so plugin link/bridge already
- # created by Airwave in that directory, or the script will not work.
- # If you don't have any Airwave *.so file in that directory, create at
- # least one with the Airwave GUI before running this script. If you
- # don't like that choice of directory, just change that option in the
- # script below. Come on, it's not rocket science.
- #
- # After running the script, open your DAW and have it refresh the list
- # of plugins (assuming it's already configured to find plugins in the
- # /usr/lib/vst directory). That's it.
- #
- # Note 1: if you're afraid of running the script, you can test it with
- # a dry run first. Just run it with any one or more arguments and see
- # what happens: the script will not do anything at all except print
- # out what it would have done if it had been run in normal mode.
- #
- # Example:
- # $ cd /some/directory/with/a/truckload/of/plugins
- # $ airblast dryrun
- #
- # Using the word 'dryrun' as argument in this example makes sense, but
- # the truth is that the script will run in dry run mode with any one
- # or more arguments of your choice. Any word at all will trigger dry
- # run mode. It's a safety mechanism against typos.
- #
- # Note 2: every time you run this script NOT in dry run mode, it makes
- # a backup copy of your airwave.conf file in the ~/.config/airwave/
- # directory. If something goes terribly wrong, use the backup file to
- # clean up the mess.
- #
- # This script is placed in the public domain.
- # No guarantees are included whatsoever. If it blows up in your face,
- # eats your files or teaches profanity to your parrot, no one will be
- # responsible.
- # If you find a bug, fix it for your own good. If you don't find any
- # bugs, rejoice. Ignorance is bliss.
- #
- # ==================================================================
- function airblast
- set -g editor "/usr/bin/vim"
- set -g target_directory "/usr/lib/vst/airwave"
- if test ! -d $target_directory
- echo "ERROR. The target directory doesn't even exist! Did you ever read the instructions???"
- echo "Please fix that problem and try again."
- echo ""
- return
- end
- set -g dryrun 0
- if test (count $argv) -gt 0
- set dryrun 1
- end
- if test -f ~/.config/airwave/found_dlls.txt
- rm -f ~/.config/airwave/found_dlls.txt
- end
- # --------------------------------
- function dllfindsub
- for i in (command ls -1a)
- if test $i = "." -o $i = ".."
- continue
- end
- if test -f "$i"
- set extension (echo $i | rev | cut -d"." -f1 | rev)
- if test $extension = "dll" -o $extension = "DLL"
- set pluginname (echo $i | rev | cut -d"." -f2- | rev)
- set fullpath (pwd | sed -r 's/.*\.wine\/(.+)/\1/')
- echo $pluginname/$fullpath/$i >> ~/.config/airwave/found_dlls.txt
- end
- end
- if test -d "$i"
- cd "$i"
- dllfindsub
- cd ..
- end
- end
- end
- # --------------------------------
- dllfindsub
- if test ! -f ~/.config/airwave/found_dlls.txt
- echo "ERROR. No DLLs found. Perhaps you're running this in the wrong directory?"
- echo ""
- return
- end
- # PAUSE TO REVIEW AND POSSIBLY EDIT THE LIST OF PLUGINS
- eval $editor ~/.config/airwave/found_dlls.txt
- # --------------------------------
- function subreview
- for i in (cat ~/.config/airwave/found_dlls.txt)
- set i (echo $i | cut -d"/" -f1)
- for j in (command ls -1a $target_directory/*.so)
- if test $j = "." -o $j = ".."
- continue
- end
- set j (basename $j .so)
- if test "$i" = "$j"
- echo "conflict: $i"
- # Note: this is supposed to be an array in fish shell fashion
- set -g conflicts $conflicts[(seq (count $conflicts))] "$i"
- end
- end
- end
- if test (count $conflicts) -gt 0
- echo ""
- echo "Uh-oh! The following names you have chosen for plugins to be added are"
- echo "in conflict with already existing ones. You can't change existing ones,"
- echo "but you can change the ones you're adding now. The list will be opened"
- echo "in the text editor again so you can edit or delete them:"
- echo ""
- for k in $conflicts
- echo "$k"
- end
- echo ""
- echo "Press Enter to continue, Ctrl-c to quit."
- read
- eval $editor ~/.config/airwave/found_dlls.txt
- else
- return
- end
- subreview
- end
- # --------------------------------
- subreview
- # --------------------------------
- # GOOD. MOVING ON...
- set timestamp (date +%Y-%m-%d_%H:%M)
- if test $dryrun = 0
- cp ~/.config/airwave/airwave.conf ~/.config/airwave/airwave.conf.backup.$timestamp
- end
- set tempfile ~/.config/airwave/airblasttemp.txt
- sed 1,4!d ~/.config/airwave/airwave.conf > $tempfile
- set anyplugin (command ls -1a $target_directory/*.so | head -n 1)
- if test $anyplugin = "."
- echo "ERROR. The target directory doesn't have any previously created link."
- echo "Please refer to the instructions, specifically this part:"
- echo ""
- echo "\"The plugin links will be created in the following directory:"
- echo "$target_directory"
- echo "Besides, you MUST have at least one *.so plugin link/bridge already"
- echo "created by Airwave in that directory, or the script will not work."
- echo "It must not be empty."
- echo "If you don't have any Airwave *.so file in that directory, create at"
- echo "least one with the Airwave GUI before running this script. If you don't"
- echo "like that choice of directory, just change that option in the script.\""
- echo ""
- return
- end
- if test $dryrun = 0
- for i in (cat ~/.config/airwave/found_dlls.txt)
- set pluginname (echo $i | cut -d"/" -f1)
- set dllpath (echo $i | cut -d"/" -f2-)
- echo " {" >> $tempfile
- echo ' "loader" : "default",' >> $tempfile
- echo ' "log_level" : -1,' >> $tempfile
- echo " \"path\" : \"$target_directory/$pluginname.so\"," >> $tempfile
- echo ' "prefix" : "default",' >> $tempfile
- echo " \"target\" : \"$dllpath\"" >> $tempfile
- echo ' },' >> $tempfile
- cp "$anyplugin" "$target_directory/$pluginname.so"
- end
- sed '5,$!d' ~/.config/airwave/airwave.conf >> $tempfile
- mv $tempfile ~/.config/airwave/airwave.conf
- else
- echo "RUNNING IN DRY RUN MODE. The following changes will NOT be applied:"
- echo ""
- for i in (cat ~/.config/airwave/found_dlls.txt)
- set pluginname (echo $i | cut -d"/" -f1)
- set dllpath (echo $i | cut -d"/" -f2-)
- echo "CREATE BRIDGE: $target_directory/$pluginname.so"
- echo "POINTING TO: $dllpath"
- echo ""
- end
- echo "END OF SIMULATION."
- echo ""
- end
- if test -f ~/.config/airwave/found_dlls.txt
- rm -f ~/.config/airwave/found_dlls.txt
- end
- if test -f ~/.config/airwave/airblasttemp.txt
- rm -f ~/.config/airwave/airblasttemp.txt
- end
- end
Add Comment
Please, Sign In to add comment