Release myth2kodi -- generate Kodi friendly file-names from MythTV recordings.
#46
(2017-03-01, 16:37)jctennis Wrote: The new version is working great.

I was thinking it might be a good idea to include some type of installer script in the download so everything could be done quickly instead of having to manually do every install step with each upgrade. I took a swing at it but I couldn't program my way out of a paper bag so I'll post what I got so far here so you can take a look. My biggest headache is getting sed to do what I want it to do. It is horribly rudimentary and has no error checking to speak of but it is my best attempt to help:
Code:
#!/bin/bash
# Ask the user for their m2kdir directory
echo What Directory do you use for your m2kdir?
read var1
#Replace m2kdir default with contents of variable
sed -i "s|$HOME/.myth2kodi|$var1|g" myth2kodi #This command does NOT work currently because I did something wrong. If I delete the $ before HOME it works but leaves the $ behind, runing the path provided by the variable
# Copy all scripts to proper directory
sudo cp myth2kodi /usr/local/bin/
sudo cp bashlogging /usr/local/bin/
sudo cp mythdb_access /usr/local/bin/
sudo cp m2k_notify /usr/local/bin/
#Set Permissions
sudo chmod o+rx /usr/local/bin/myth2kodi
sudo chmod o+rx /usr/local/bin/mythdb_access
sudo chmod o+rx /usr/local/bin/m2k_notify

Yeah, I have considered this... The reason that I have not, so far,
added an install script is that adding one that works robustly will
require a lot of testing and checking. I will most likely do this
eventually, but for the moment I have things I want to focus on that
I consider higher priority.

From experience I know that a simple script, like the one you propose,
will cause more problems than it solves -- at least, if I officially
add it to the myth2kodi repository and people use it blindly. That
being said, I understand the desire to automate the process. So, for
the sed in your script, you were close, just off with the quoting a
bit, what you want is:
Code:
sed -i 's|$HOME/.myth2kodi|'"$var1"'|g' myth2kodi
Single quotes prevent the expansion of parameters, so '$HOME' will remain
'$HOME' instead of expanding to '/home/mythtv' or whatever. You want
var1 to expand, so it is in double quotes "$var1". The only other thing
to know is that if you put strings against one another with no spaces
then they basically get treated like one string, that is:
'str1'"str2"'str3' == 'str1str2str3'.

Though, to avoid replacing the default value in the comment line above the
m2kdir= expression, you could be more specific and including the m2kdir=
in your pattern, so:
Code:
sed -i 's|m2kdir="$HOME/.myth2kodi"|m2kdir="'"$var1"'"|g' myth2kodi
will only substitute the setting of m2kdir. The key thing to know here is
that if you put single quotes inside double quotes, or double quotes inside
single quotes, then the quotes inside are just treated as characters in your
string and do not have a special meaning. So the double quotes in
m2kdir="$HOME/.myth2kodi" are just part of the string and do not
cause parameter expansion. Whereas with m2kdir="'"$var1"'", the double
quotes closest to $var1 allow parameter expansion and disappear while
the next set of double quotes are inside the adjacent single quote blocks and
so remain part of the string being substituted.
Reply


Messages In This Thread
RE: myth2kodi -- generate Kodi friendly file-names from MythTV recordings. - by stuartk - 2017-03-02, 07:17
Logout Mark Read Team Forum Stats Members Help
myth2kodi -- generate Kodi friendly file-names from MythTV recordings.2