pouët.net

Here's a script to automate the launch of Win and DOS demos in Linux.

category: code [glöplog]
 
Decided to write a Bash script to make things faster.
It only takes 1 argument, the demo archive or the existing demo directory.
It's menu based so no command line options.

example: thisscript.sh /mnt/dvd/demoname.zip

Code: #!/bin/bash FileReader=less FileEditor=vim exepath="" demopath="" exename="" workdir="" separator="=================== " function fnError { echo ERROR $@ echo echo "Usage: startdemo.sh <demo archive or directory>" } function fnSplitPath { exename=$(basename "$exepath") workdir=$(echo "$exepath" | sed -e 's,/[^/]\+$,,g') #echo -e "executable="$exename \\n"working directory="$workdir \\n } function fnWineMenu { #got Wine? wine --version &>/dev/null if [ $? -ne 0 ]; then echo "But you don't have Wine :(" return fi cd "$workdir" #show menu local isDone=0 local items=('Configure' 'Toggle explorer use' 'Launch' 'Cancel') local options="" while [ $isDone -eq 0 ]; do echo -e ${separator}Wine menu if [ -z "$options" ]; then echo "explorer [OFF]" else echo "explorer [ON]" fi select i in "${items[@]}"; do #configure Wine if [ "$i" = "${items[0]}" ]; then winecfg #toggle explorer use elif [ "$i" = "${items[1]}" ]; then if [ -z "$options" ]; then options="explorer /desktop=iPityTheFool,1024x768" else options="" fi #launch elif [ "$i" = "${items[2]}" ]; then wine $options "$exename" #done else isDone=1 fi break done done } function fnDosMenu { #got DOSBox? dosbox --version &>/dev/null if [ $? -ne 0 ]; then echo "But you don't have DOSBox :(" return fi #use default config as a template local template=$(dosbox -printconf) #create dosbox config file if it doesn't exist local dosboxconf=~/.dosbox/demo_$(basename "$workdir")-dosbox.conf cd "$workdir" if [ ! -f "$dosboxconf" ]; then if [ ! -f "$template" ]; then echo "ERROR no dosbox template!" return fi cp "$template" "$dosboxconf" #assume 'autoexec' section is at the end echo -e "mount w $workdir" \\nw: \\n$exename \\n >> "$dosboxconf" echo Created "$dosboxconf" fi #show menu local isDone=0 local items=('Configure' 'Launch' 'Cancel') while [ $isDone -eq 0 ]; do echo -e ${separator}DOSBox menu select i in "${items[@]}"; do #configure dosbox if [ "$i" = "${items[0]}" ]; then $FileEditor "$dosboxconf" #launch elif [ "$i" = "${items[1]}" ]; then dosbox -conf "$dosboxconf" #done else isDone=1 fi break done done } function fnMain { # is first argument the demo directory? if [ -d "$1" ]; then cd "$1" demopath=$(pwd) # or is it the demo archive (assuming zip format) elif [ -f "$1" ]; then local prefixpath=/tmp/demos demopath=${prefixpath}/$(basename "$1" | sed -e 's,\.[a-zA-Z0-9]\+$,,g') local suffix=$(echo "$1" | sed -e 's,.*\.\([a-zA-Z0-9]\+\)$,\U\1,g') #echo $suffix #extract it if directory doesn't exist if [ ! -d "$demopath" ]; then #create dir mkdir -p -v "$demopath" #zip if [ "$suffix" = "ZIP" ]; then unzip "$1" -d "$demopath" if [ $? -ne 0 ]; then fnError "could not unzip" return fi #rar elif [ "$suffix" = "RAR" ]; then unrar x "$1" "$demopath" if [ $? -ne 0 ]; then fnError "could not unrar" return fi #fail else fnError "not an archive" return fi fi else fnError "invalid demo" return fi # OK we have the demo path echo -e ${separator}\\n"demo path="$demopath \\n #find all exe location and readme files local IFS=':' local exelist=($(find $demopath \( -iname '*.exe' -o -iname '*.com' \) -printf "%p:")) local nfolist=($(find $demopath \( -iname '*.nfo' -o -iname '*.diz' -o -iname '*.txt' \) -printf "%p:")) IFS=' ' local helpmenu=('Cancel' "${nfolist[@]}") if [ ${#exelist[@]} -eq 0 ]; then fnError "no executable found" return fi exepath=${exelist[0]} #split path from exe fnSplitPath #show main menu local isDone=0 local items=('Run Win demo' 'Run DOS demo' 'Choose EXE' 'HELP' 'Quit') while [ $isDone -eq 0 ]; do echo -e ${separator}\\n"EXE="$exepath echo -e ${separator}Main menu select i in "${items[@]}"; do #windows if [ "$i" = "${items[0]}" ]; then fnWineMenu #DOS elif [ "$i" = "${items[1]}" ]; then fnDosMenu #Choose executable elif [ "$i" = "${items[2]}" ]; then echo ${separator}Executable list select j in "${exelist[@]}"; do if [ -n "$j" ]; then exepath="$j" else echo no change fi break done fnSplitPath #view info files elif [ "$i" = "${items[3]}" ]; then if [ ${#nfolist[@]} -gt 0 ]; then echo -e ${separator}Help menu select j in "${helpmenu[@]}"; do #quit if [ "$j" = "${helpmenu[0]}" ]; then break #view file elif [ -f "$j" ]; then $FileReader "$j" #not a problem here if file reader gives back control to tty after starting, #it will go back to top menu and wait else break fi done else echo -e "No info files for this demo" \\n fi else isDone=1 fi break done done echo DONE } fnMain $@
added on the 2012-08-07 01:45:05 by duffman duffman
Updated the fnDosMenu function. Creating a config file for each dos demo was a waste. Now it's the same file for all.
Code: function fnDosMenu { #got DOSBox? dosbox --version &>/dev/null if [ $? -ne 0 ]; then echo "But you don't have DOSBox :(" return fi #use default config as a template local template=$(dosbox -printconf) #create dosbox config file if it doesn't exist local dosboxconf=~/.dosbox/demos_dosbox.conf cd "$workdir" if [ ! -f "$dosboxconf" ]; then if [ ! -f "$template" ]; then echo "ERROR no dosbox template!" return fi cp "$template" "$dosboxconf" echo Created "$dosboxconf" fi #show menu local isDone=0 local items=('Configure' 'Launch' 'Cancel') while [ $isDone -eq 0 ]; do echo -e ${separator}DOSBox menu select i in "${items[@]}"; do #configure dosbox if [ "$i" = "${items[0]}" ]; then $FileEditor "$dosboxconf" #launch elif [ "$i" = "${items[1]}" ]; then dosbox -conf "$dosboxconf" -noautoexec "$exename" #done else isDone=1 fi break done done }
added on the 2012-08-07 06:59:04 by duffman duffman
Nice work. Don't use DOSBox on Linux though :/
Sometimes DOSBox need specific options for the demo to run (no XMS, GUS, whatnot), so a specific configuration for every demo might be necessary.

Having a fast machine with this and a DVD-style menu as a frontend would be sweet. DOS demoplayer... ;)
added on the 2012-08-07 09:35:37 by raer raer
as in "...I don't use..."
added on the 2012-08-07 09:36:01 by raer raer

login