Jump to content

Script to Create Directory, Set Permissions, and Move File


Recommended Posts

Posted

Hi All:

I'm a Linux Mint user. I've read the Linux file permissions thread and tried "sudo setfacl -R -m d:jarl:emby:rwX /home/emby" to give Emby the permission to drop art and nfo files into media folders but that returned the following error: "setfacl: Option -m: Invalid argument near character 8"

I am not a Linux guru by any stretch but I understand what the file permission/ownership issues are and I can get the permissions set this way (hopefully no typos here):

sudo mkdir "/home/emby/Movies/Jack Frost (1979)"

sudo chown jarl:emby "/home/emby/Movies/Jack Frost (1979)"

sudo chmod -R g+w "/home/emby/Movies/Jack Frost (1979)"

sudo mv "/home/jarl/Videos/Jack Frost (1979).mkv" "/home/emby/Movies/Jack Frost (1979)/Jack Frost (1979).mkv"

sudo chown jarl:emby "/home/emby/Movies/Jack Frost (1979)/Jack Frost (1979).mkv"


But what I would like to have is a script that I pass the title of the movie to and it runs the commands above for me substituting in the title I pass it, like thus:

A pseudo moviescript.sh where $STRINGPARAMETER = i.e. "Jack Frost (1979)"

sudo mkdir "/home/emby/Movies/" & $STRINGPARAMETER

sudo chown jarl:emby "/home/emby/Movies/" & $STRINGPARAMETER

sudo chmod -R g+w "/home/emby/Movies/" & STRINGPARAMETER

sudo mv "/home/jarl/Videos/" & $STRINGPARAMETER & ".mkv" "/home/emby/Movies/" & $STRINGPARAMETER & "/" & $STRINGPARAMETER & ".mkv"

sudo chown jarl:emby "/home/emby/Movies/" & $STRINGPARAMETER & "/" & $STRINGPARAMETER & ".mkv"


I think to run scripts you just have to make a text file executable and call it with a dot, like so:

.moviescript -title="Jack Frost (1979)"


Anyway, there's probably a more elegant solution and obviously I don't know how to pass an argument to a script file so any help would be much appreciated.

Posted (edited)

So i just did a quick test and you could try working with this as a baseline

In my example, i wanted to pass two arguments with the command so that it would rename a file, to another name

Create a script

nano myscriptname.sh

Then in this script enter your commands, in my example i have this

#!/bin/bash
sudo mv /Download/$1  /Download/$2
echo " Your file: $1 has been renamed to: $2 "

The key points here are $1 and $2, these are the two variables i am passing, the first $1 is the original filename you want to affect and the second is what i want it to be called

Obviously adjust paths how ever you need

SO now if i run the following command in terminal :

sh rename.sh rename.mkv ihavebeenrenamed.jpg

For reference

  • $1 if the first word after the script name i.e rename.mkv
  • $2 is the second word after the script name i.e ihavebeenrenamed.jpg 

 

I am telling the script which is called rename.sh and processed using the SH command, TO RENAME the file rename.mkv to ihavebeenrenamed.jpg

The echo line, just prints out what is written in quotes, again taking the $1 and $2 values.

Again this was just a quick and dirty example that i created to show you how to pass the varibale

Just done a quick video on my homelab pi setup to show you what the above means and does

 

Edited by CassTG
Posted (edited)

Finally, i just tested what you want to do and this should work as i have tested it again obviously adjust accordingly

#!/bin/bash
echo "I am now processing your file $1"
sudo mkdir /scriptexample/$1
echo "I have created folder - /home/emby/Movies/$1 Moving on to next stage"
sudo chown CassTG:CassTG /scriptexample/$1
echo "I have changed the ownership of the folder - /home/emby/Movies/$1 Moving on to next stage"
sudo chmod -R g+w /scriptexample/$1
echo "I have changed the permissions of the folder - /home/emby/Movies/$1 Moving on to next stage"
sudo mv /scriptexample/$2 /scriptexample/$1/$2
echo "I have moved the movie to the correct folder... Moving on to next stage"
sudo chown CassTG:CassTG /scriptexample/$1/$2
echo " I have changed ownership of movie file $2 in folder $1"

Changed owners and paths accordingly

You can see the script in action here

One thing to note, however if you are calling the folder in standard format i.e FilmFolder (1990) then you will need to put that folder in quotes "FilmFolder (1990)" else that will be variable 1 and 2 in error

 

Edited by CassTG
Posted

I have been working on it too after your first post. It will be fun to compare. TY for the help, it's already working but I've got a couple of tweaks I'm putting in. This is WONDERFUL.

  • Like 1
Posted
3 minutes ago, usTom said:

I have been working on it too after your first post. It will be fun to compare. TY for the help, it's already working but I've got a couple of tweaks I'm putting in. This is WONDERFUL.

No probs, just added video on the working version but least you got it sorted and i also learnt something in the process lol

Posted

CassTG I think this will be very useful for folks. My Linux server died a couple of years ago and I'm just now rebuilding it. I had this same issue when I first had Emby setup and it was a nightmare playing with ACL's and the sticky bit and all sorts of fixes. IIRC I ended up using Filezilla to FTP in and if you have FTP host setup correctly that worked pretty good for me. But what you have shown me here is awesome and hopefully people will get directed here, maybe even a FAQ developed on it. Because Linux don't Windows when it comes to security and file permissions.

Posted (edited)

Here is what I came up with:

 

#!/bin/bash

#I named the script file "postmovie.sh"
#To enable you must make postmovie.sh executable i.e. sudo chmod u+x postmovie.sh
#To execute run "sh postmovie.sh "Title of Movie with Publication Year" "file extension of movie" (i.e avi, mkv, etc.)
#Change the chown USER in the script below to an administrator on your Linux machine i.e. [chown -R adminguy:emby "/home/emby/Movies/$1"]
#Change the (move from) and (move to) directories for your case use and you should be good to go!
#Note: This will make the target file read/write by the user, read only by the group and unaccessible for everyone else. This may be too strict for certain Emby use cases, not sure. If you are having problems you might want to change the first chmod to 775 and-or the second chmod to 644 or 664.
#This does not error trap for spelling errors, etc. so make sure you use the existing filename exactly (Linux is case sensitive) or may have to go in manually to delete erroneously made folders.

sudo mkdir "/home/emby/Movies/$1"

sudo mv "/home/jarl/Videos/$1.$2" "/home/emby/Movies/$1/$1.$2"

sudo chmod 770 "/home/emby/Movies/$1"

sudo chmod 640 "/home/emby/Movies/$1/$1.$2"

sudo chown -R jarl:emby "/home/emby/Movies/$1"

echo $1 $2 " has been moved to /home/emby/Movies/$1" 

echo "Thanks to CassTG on the Emby Community Forums for teaching me how to pass parameters to, and concatenating them inside, a simple script!"

 

Edited by usTom
  • Thanks 1
Posted

If someone knows how to exit the script should the $1.$2 file not be found that would be sweet.

mastrmind11
Posted
16 hours ago, usTom said:

If someone knows how to exit the script should the $1.$2 file not be found that would be sweet.

this should get you started:

[[ -z "$1" ]] && { echo "Parameter 1 is empty" ; exit 1; }

 

Posted

@usTom Okay so i was bored this Christmas Eve as i was well prepared this year so whilst cooking up the gammon i thought i would try something new.

First off i should point out this fact, up until i had the idea to make your idea interactive i have never ever written a python script in my life, always wanted to learn and never had the reason too until now. So apologies to you Python Guru's as no doubt you will look at this and think OMG what the hell are they doing.

That said, this is an interactive and slower version and brings no benefit except to a real novice user who needs guiding step by step.

The script will:

  • Request existing folder location
  • request file name to be renamed and moved
  • Request folder and thus file title name
  • Set permissions how you did in your version
  • Opens up the /etc/passwd so you can enter the GID and UID correctly
  • Create the folders and set permission
  • moves the file
  • Asks if you wanna ride again

As stated please don't have a go if you think you could of done this in like 5 lines, as i said i have never ever written in python ever before so this is my first go.

Requirements

  • Python 3 must be installed

Create a file called embyfiles.py

nano embyfiles.py

Copy the following code for the script into the file you just opened

#!/usr/bin/env python3

import shutil
import os
import time
import sys

print("This script will take the answers you provide, to rename a Folder/File and move to your Emby media folder and then set the correct permissions")

#This question will request the  folders original location
originalfolder = input("Please enter the full path containing the original folders include trailing slash i.e /path/to/folder/:  ")
#This question will request the original filename
originalfilename = input("Please enter the filename to be moved exluding extension (i.e file.mkv you would enter just file): ")
#This question will request the  destination folders location
destinationfolder = input("Please enter the full path where you wish to move the folders too (include forward and trailing slash i.e /new/folder/path/:  ")
#This question will request the  folder name you want to apply
foldername = input("Enter the new folders name:  ")
#This question will request the extension of the file
fileextension = input("Enter the file extension include the period full stop , i.e .mkv or .mp4:  ")
#Open /etc/passwd to display user IDS
print(" I will now open up the user list for this system so you can pick your UID username and emby's Group name (should be emby)")
time.sleep(4)
os.system('clear')
passwd = open("/etc/passwd")
lines= passwd.readlines()
for line in lines:
    print(line)
passwd.close()
#This question will request the user ID the folder should be assigned to
uid = input("Enter the USER ID (the name not numerical number) to be assigned to the new folder (case sensitive):  ")
#This question will request the Group ID for emby the folder should be assigned to
gid = input("Enter the GROUP ID for EMBY (the name not numerical number default should be emby) to be assigned to the new folder (case sensitive):  ")
#This prints a summary of the answers provided
print("So I am going to make a new folder called - " + foldername + ", which will be placed in  - " + destinationfolder + " and will rename the file - " + originalfilename + fileextension + " TO - " + foldername + fileextension)
#This prints a pause notice and option to cancel
print("Preparing to proceed with your request, will commence actions in  5 seconds to CANCEL press Ctrl+C")
time.sleep(5)
#Create Folder & print a commencing statement
fullpath = destinationfolder + foldername
print("Creating new folder in - " + fullpath)
os.mkdir(fullpath, mode=0o770, dir_fd=None);
os.chmod(fullpath, 0o770);
time.sleep(3)
#Changing ownership of folder
print("Changing ownership of  - " + fullpath)
shutil.chown(fullpath,user=uid,group=gid)
time.sleep(3)
#Move File from existing location to newly created folder
print("Moving original file to new folder.....")
fulloriginalfilepath = originalfolder + originalfilename + fileextension
Fullnewfilepath = fullpath + "/" + foldername + fileextension
shutil.move( fulloriginalfilepath, Fullnewfilepath );
time.sleep(3)
#set permission on newly created file
print("Setting the correct permissions to the file just created.....")
os.chmod(Fullnewfilepath, 0o640)
time.sleep(3)
#File completion
print("Your folder has been created and the file renamed and moved to it's correct location, all permission have been set correctly for emby to access the file")
#Move another file option
rerun = input("Would you like to move another file (y/n only) :")
if rerun =="n":
   exit()
elif rerun=="y":
   os.execv(sys.argv[0], sys.argv)

Then to save and close

ctrl o
ctrl x

 

You may need to set the script as executable to run

To run enter:

python3 embyfiles.py

and follow the instructions to the letter

 

Anyways was just for fun, i have no use for it as i use docker and all is sweet there, heres a video of it in action on my homelab pi

 

 

embyfiles.py

Posted (edited)
4 hours ago, mastrmind11 said:
this should get you started:

[[ -z "$1" ]] && { echo "Parameter 1 is empty" ; exit 1; }

 

I'll see about incorporating it. I'm no programmer though and unable to interpret exactly how this would work.

I assume the double square brackets means something like evaluate(expression). No idea what -z does. Perhaps not exist? Then if, and only, if $1 does not exist the print to screen Parameter 1 is empty and then exit the script. All guesses though. But is this checking for the file to exist or just that a parameter was passed. That's my best guess. Sorry I don't have terminal or programming expertise.

If there's a good primer, or video series out there folks could recommend I'd be interested!

Edited by usTom
Posted
2 hours ago, CassTG said:

That said, this is an interactive and slower version and brings no benefit except to a real novice user who needs guiding step by step.

This is really cool and could serve not only as a help to the novices who have Linux file permission issues (like me) that seem to be a recurring problem, it also serves as a mini-primer for python scripting for those that are minimally savvy enough to follow along with the tasks being handled. Nice!

Setting up the Emby server over the Christmas Holiday has been keeping me busy/entertained whilst waiting for the grandkids to come visit. :) Merry Christmas all!

Posted (edited)
26 minutes ago, usTom said:

This is really cool and could serve not only as a help to the novices who have Linux file permission issues (like me) that seem to be a recurring problem, it also serves as a mini-primer for python scripting for those that are minimally savvy enough to follow along with the tasks being handled. Nice!

Setting up the Emby server over the Christmas Holiday has been keeping me busy/entertained whilst waiting for the grandkids to come visit. :) Merry Christmas all!

Merry Christmas to you too.

And yes indeed makes a change from watching crimbo movies, i needed summin linuxy to take me mind off the big day lol, so whacked on scrooged and got to work on it, the script will end of the filename is not found automatically, and also will not allow a folder to be created if you already have that folder in place.

I throughly enjoyed learning the python, as its quite logical and easy to understand. As it works top down its very easy to work out whats going on, and i've only made use of simple variables.

For example:

Quote
foldername = input("Enter the new folders name:  ")

foldername is the variable which i can call up later, we get the value of that variable by using the input statement which is what ask's the question, so what you type in becomes that variable

so later on it pops up here

Fullnewfilepath = fullpath + "/" + foldername + fileextension

Again i am creating a new variable using 3 existing variables (inc foldername)

So the new variable Fullnewfilepath is made up of fullpath + / +foldername + fileextensionm which would look like this:

/my/folder/location    /    myfolder (2020).mkv

that way when chmod/chown we just call on the variable Fullnewfilepath as seen here

os.chmod(Fullnewfilepath, 0o640)

And once ya get ya head around the logic it really is simple to figure out and amend, i.e if you are the only user on your system you could just cut out the open passwd section and set the variables gid and uid at the top instead

And i am just thankful i went the docker route, as boom no permission errors ever lol i likle the easy options lol

Edited by CassTG
Posted
14 minutes ago, CassTG said:

And once ya get ya head around the logic it really is simple to figure out and amend, i.e if you are the only user on your system you could just cut out the open passwd section and set the variables gid and uid at the top instead

Yeah I think I can follow your script 99%. Not sure what

3 hours ago, CassTG said:
os.execv(sys.argv[0], sys.argv)

is there but the rest of it I think I got. Back in the olden days I programmed in Visual Foxpro a program that read print to file text meant to go onto health insurance claim forms and my program would read those files generated by the medical billing software and reformat them into file formats accepted by the electronic clearinghouses, then using libraries available for Foxpro I'd connect to the clearinghouse (via of modem or even this new-fangled thing called internet/ftp protocol) and transmit the file. Also, played around with the visual basic a bit and the basic language in Open Office to automate a ton of office functions where I used to work. So, I've dabbled a bit here and there intermittently with this stuff but I've never committed to becoming a full blown professional or even a dedicated hobbyist by any means. For whatever reason, I find these small projects, finish and move on, to be fun!

Posted
48 minutes ago, usTom said:
os.execv(sys.argv[0], sys.argv)

Yeah all that does if if they want to repeat the script for another file by selecting yes, that just re-executes the script using the same command variables it was started with (i.e in this case python3 embyfiles.py) without exiting.

And i agree totally, i like unique challenges but get bored easily, so i try summin, research it, complete it then move on as i get bored quickly.

 

  • Like 1
Posted (edited)

Decided to continue and play with this and create a little Emby Server manager script in python, just for mucking about reasons, and looking at frequently asked questions by newbies on here where this would ease the pain a little.

Anyways only continued this as the OP piqued my interest in starting to learn python, and now im hooked so gonna build on this.

For now the following options are avaliable in a menu driven script:

1449675034_Screenshot2021-12-27at16_42_58.thumb.png.af770d989f76c1d2236fa49cbf3f9fd0.png

  1. Is the OP request on renaming/moving/setting permission on a single file
  2. Sets the correct folder ownership for media folders only as per OP settings (correct Emby requirements?)
  3. Sets the correct file permissions to media files only as per OP settings
  4. This pulls up the list of UID and GID so you can easily find what you need to enter in option 2
  5. A common request on the forums, this option will do the following:
    • Pull up a list of currently running dockers so you can get container name
    • request container name to stop
    • ask for data folder location
    • gracefully stop emby container
    • remove the Activity database
    • Restart the docker container
  6. Same as 5 but stops emby server via systemctl command and deletes the activity database in it's common path (tested on Ubuntu/Debian/Centos/Fedora but not yet Alpine etc)
  7. Deletes all *.txt files in logs folder for docker
  8. Deletes all *.txt files in logs folder for Ubuntu/Debian/Centos/Fedora

This is only for a bit of fun and learning, but going to look to add a load more stuff, trying to find certain documentation for Emby is literally impossible (i.e would like to trigger a log rotation after deleting so a new log is immediately avaliable etc). Also want to be able to automatically search for folder paths and set them as variables so users do not have to enter them. However will also create a version where the user can enter the variables once in a seperate file that sits alongside, that way they only need to be entered once.

Heres a video showing it in action now, chapter markers also so you can skip to sections

 

Edited by CassTG
  • 2 weeks later...
Posted
On 12/27/2021 at 8:56 AM, CassTG said:
  • Sets the correct folder ownership for media folders only as per OP settings (correct Emby requirements?)
  • Sets the correct file permissions to media files only as per OP settings

Hi CassTG:

Just wrapped up the holidays and rebuilding my old PC into a server and setting up a new personal PC to multiboot into Mint, EndeavourOS, Pop!, Fedora, and Windows 10. Tons of fun playing with partitions, UEFI, etc. I got to say, Anyway, came back here to look up how to recursively set file permissions only and folder permissions only. And lo and behold you now have a script for doing just that, but I don't see the script?

Posted (edited)

Hold on a second, it's because i came up with another idea lol which im working on, let me grab the script that does that but obviously use at ya own risk lol

Update: Script added as always run a test on a few madeup folders and files to make sure your happy, i did test it when i wrote it but only on debian/ubuntu and i think centos

Save file as embymanager.py, make executable, and run as python3

 

#!/usr/bin/env python3

import shutil
import os
import time
import sys
import subprocess

#Menu options display
print(" Preparing environment and loading user menu")
time.sleep(3)
os.system('clear')
print("Welcome to Emby Manager, this small utility will help users manage their server backend, it is provided without any warranty and should be used with caution, any issues should be reported in the thread located here:")
print(' ')
print(' ')
menu_options = {
    1: 'Create correctly titled folder, rename file and move to your media directory and apply Emby required permissions',
    2: 'Recursevly apply folder permissions ONLY',
    3: 'Recursevly apply file permissions ONLY',
    4: 'View User Ids as required above',
    5: 'Delete Emby Activity DB - DOCKER',
    6: 'Delete Emby Activity DB - Ubuntu/Centos/Debian/Fedora',
    7: 'Delete All LOGS - DOCKER',
    8: 'Delete ALL LOGS - Ubuntu/Centos/Debian/Fedora',
    9: 'Exit'
}

def print_menu():
    for key in menu_options.keys():
        print (key, '--', menu_options[key] )

def option1():
     print('Handle option \'Option 1\'')

def option2():
     print('Handle option \'Option 2\'')

def option3():
     print('Handle option \'Option 3\'')

def option4():
     print('Handle option \'Option 4\'')

def option5():
     print('Handle option \'Option 5\'')

def option6():
     print('Handle option \'Option 6\'')

def option7():
     print('Handle option \'Option 7\'')

def option8():
     print('Handle option \'Option 8\'')

def option9():
     print('Handle option \'Option 9\'')

if __name__=='__main__':
    while(True):
        print_menu()
        option = ''
        try:
            option = int(input('What would you like to do? Please enter your choice: '))
        except:
            print('Wrong input. Please enter a number between 1 and 9 ...')
        #Check what choice was entered and act accordingly
        if option == 1:
           print("You have choosen to undertake all processes....Now Loading your configuration")
           time.sleep(2)
           os.system('clear')
           print("This script will take the answers you provide, to rename a Folder/File and move to your Emby media folder and then set the correct permissions")

           #This question will request the  folders original location
           originalfolder = input("Please enter the full path containing the original folders include trailing slash i.e /path/to/folder/:  ")
           #This question will request the original filename
           originalfilename = input("Please enter the filename to be moved exluding extension (i.e file.mkv you would enter just file): ")
           #This question will request the  destination folders location
           destinationfolder = input("Please enter the full path where you wish to move the folders too (include forward and trailing slash i.e /new/folder/path/:  ")
           #This question will request the  folder name you want to apply
           foldername = input("Enter the new folders name:  ")
           #This question will request the extension of the file
           fileextension = input("Enter the file extension include the period full stop , i.e .mkv or .mp4:  ")
           #Open /etc/passwd to display user IDS
           print(" I will now open up the user list for this system so you can pick your UID username and emby's Group name (should be emby)")
           time.sleep(4)
           os.system('clear')
           passwd = open("/etc/passwd")
           lines= passwd.readlines()
           for line in lines:
               print(line)
           passwd.close()
           #This question will request the user ID the folder should be assigned to
           uid = input("Enter the USER ID (the name not numerical number) to be assigned to the new folder (case sensitive):  ")
           #This question will request the Group ID for emby the folder should be assigned to
           gid = input("Enter the GROUP ID for EMBY (the name not numerical number default should be emby) to be assigned to the new folder (case sensitive):  ")
           #This prints a summary of the answers provided
           print("So I am going to make a new folder called - " + foldername + ", which will be placed in  - " + destinationfolder + " and will rename the file - " + originalfilename + fileextension + " TO - " + foldername + fileextension)
           #This prints a pause notice and option to cancel
           print("Preparing to proceed with your request, will commence actions in  5 seconds to CANCEL press Ctrl+C")
           time.sleep(5)
           #Create Folder & print a commencing statement
           fullpath = destinationfolder + foldername
           print("Creating new folder in - " + fullpath)
           os.mkdir(fullpath, mode=0o770, dir_fd=None);
           os.chmod(fullpath, 0o770);
           time.sleep(3)
	   #Changing ownership of folder
           print("Changing ownership of  - " + fullpath)
           shutil.chown(fullpath,user=uid,group=gid)
           time.sleep(3)
	   #Move File from existing location to newly created folder
           print("Moving original file to new folder.....")
           fulloriginalfilepath = originalfolder + originalfilename + fileextension
           Fullnewfilepath = fullpath + "/" + foldername + fileextension
           shutil.move( fulloriginalfilepath, Fullnewfilepath ); 
           time.sleep(3)
	   #set permission on newly created file
           print("Setting the correct permissions to the file just created.....")
           os.chmod(Fullnewfilepath, 0o640)
           time.sleep(3)
	   #File completion
           print("Your folder has been created and the file renamed and moved to it's correct location, all permission have been set correctly for emby to access the file")
           time.sleep(3)
           os.system('clear')
        elif option == 2:
           #Request root Media Path
           mediarootfolder = input("Please enter the full ROOT path of your Emby Media Files (include forward and trailing slash i.e /new/folder/path/:  ")
           #This question will request the user ID the folder should be assigned to
           uid2 = input("Enter the USER ID (the name not numerical number) to be assigned to the new folder (case sensitive):  ")
           #This question will request the Group ID for emby the folder should be assigned to
           gid2 = input("Enter the GROUP ID for EMBY (the name not numerical number default should be emby) to be assigned to the new folder (case sensitive):  ")
           #Changing ownership of folder
           print("Changing ownership of  - " + mediarootfolder)
           os.system('find ' + mediarootfolder + ' -type d -exec chown ' + uid2 + ':' + gid2 + ' {} + ')
           time.sleep(3)
           print(' Your folder ownership has been changed as requested, exiting to main menu')
           time.sleep(3)
           os.system('clear')
        elif option == 3:
           mediarootfolder2 = input("Please enter the full ROOT path of your Emby Media Files (include forward and trailing slash i.e /new/folder/path/:  ")
           #Changing permissions of the files only
           print("Changing permissions of files located in  - " + mediarootfolder2 + " this may take a while - ")
           os.system('find ' + mediarootfolder2 + ' -type f -exec chmod 640 {} + ')
           time.sleep(3)
           print(' Your file permissions have been changed as requested, exiting to main menu')
           time.sleep(3)
           os.system('clear')
        elif option == 4:
           #Open /etc/passwd to display user IDS
           print(" I will now open up the user list for this system so you can pick your UID username and emby's Group name (should be emby)")
           time.sleep(4)
           os.system('clear')
           passwd2 = open("/etc/passwd")
           lines= passwd2.readlines()
           for line in lines:
               print(line)
           passwd2.close()
           #Rerun Menu
           rerun4 = input("Would you like to return to the Emby Manager Menu y/n only :")
           if rerun4 =="n":
              print('Thanks for using Emby Manager, i hope you found this script useful.')
              exit()
           elif rerun4=="y":
                print("Reloading Main Menu........")
                time.sleep(2)
                os.system('clear')
                os.execv(sys.argv[0], sys.argv)
        elif option == 5:
           #Stop docker and delete activity log 
           print('I will now show you the list of running containers, please look for your emby containers NAME: ')
           time.sleep(3)
           os.system('clear')
           os.system('docker ps -a')
           containername = input("Please enter the docker hostname (i.e Emby - case sensitive):  ")
           logdblocation = input("Please enter the full path to your Emby Docker Volume i.e /var/lib/docker/volumes/yourcontainername/data:  ")
           print(" I will now shut down the emby docker container so we can delete the activity database, upon completion i will bring the container back online")
           print("Shutting down the container in 5 seconds")
           time.sleep(2)
           os.system('docker stop ' + containername)
           os.system('clear')
           print("Docker " + containername + " has been stopped, now deleting the Activity Log")
           time.sleep(2)
           os.system('rm ' + logdblocation + 'activitylog.db')
           time.sleep(2)
           print("The activity log has now been deleted, attempting to restart your " + containername + 'docker container')
           os.system('docker start ' + containername)
           print("Docker " + containername + " has been started")
           time.sleep(3)
           os.system('clear')
        elif option == 6:
           #Stop Emby Server and delete activity log
           print(" I will now shut down the emby server so we can delete the activity database, upon completion i will bring the server back online")
           print("Shutting down the server in 5 seconds, press CTRL+C to cancel")
           time.sleep(5)
           os.system('systemctl stop emby-server')
           print("Emby Server has been stopped, now deleting the Activity Log")
           time.sleep(2)
           os.system('rm /var/lib/emby/data/activitylog.db')
           time.sleep(2)
           print("The activity log has now been deleted, attempting to restart your Emby Server")
           os.system('systemctl start emby-server')
           print("Checking your server has started correctly and then exiting to main menu -")
           time.sleep(3)
           os.system('clear')
        elif option == 7:
           #Delete all Emby Logs - Docker
           loglocation = input("Please enter the full path to your docker volume and log folder, i.e /var/lib/docker/volumes/YOURVOLUME/logs/ inc end slash:  ")
           print('This option will delete all embyserver.txt, hardware-detection.txt and ffmpeg log files, starting in 5 seconds press ctrl+c to cancel: ')
           time.sleep(5)
           os.system('rm ' + loglocation + '*.txt')
           print('All logs have been deleted, to restart logging visit Emby - Scheduled tasks and click rotate log - Returning to main menu')
           time.sleep(5)
           os.system('clear')
        elif option == 8:
           #Delete all Emby Logs - OS Level
           print('This option will delete all embyserver.txt, hardware-detection.txt and ffmpeg log files, starting in 5 seconds press ctrl+c to cancel: ')
           time.sleep(5)
           os.system('rm /var/lib/emby/logs/*.txt')
           print('All logs have been deleted, to restart logging visit Emby - Scheduled tasks and click rotate log - Returning to main menu')
           time.sleep(5)
           os.system('clear')
        elif option == 9:
            print('Thanks for using Emby Manager, i hope you found this script useful.')
            exit()
        else:
            print('Invalid option. Please enter a number between 1 and 9.')

 

Edited by CassTG
  • Thanks 1
Posted

And thought i would start work on an extended script which can be used by Newbies to setup a complete docker stack and fully working and secured Emby setup withoput any knowledge, This version has a separate config file where you only have to enter key setup info once, and then the script pulls in the variables when needed so the Turbo version is whats been added:

1038304852_Screenshot2022-01-11at16_32_45.thumb.png.f6c9b34cc8260d8a6051751ff7aef526.png

So currently the turbo script will ona fresh server with only python3 installed:

  • Update the system
  • Pull dependencies and install
  • Pull down docker framework and install
    • Creates a seperate docker network
    • Creates persistant volume storage location
  • Pull down the Linuxserver Swag docker
    • Obtain the certs for the provided domain and subdomains via zerossl
    • Assigns docker ip fixed
    • Stops docker pending more info
    • Assigns persistant volumes
  • Pulls down portainer docker
    • sets Fixed Ip address
    • Opens port 9000 temporarily
    • Assigns persistant volumes
  • Pulls down Emby Docker (latest or beta defined in config)
    • Sets fixed Ip address
    • Sets up with correct flags for HW passtrhough
    • Persistant storage

Thats as far as i have got but what will happen next is:

  • Subdomains entered in config will be applied to the relevant Swag proxy-confs files
  • Emby config will be updated with correct network port settings and domain names out of the box
  • UFW firewall will be activated and iptables adjusted for correct docker firewall handling
  • All unneeded ports removed from dockers

And then im adding a backup option for moving emby docker from one server to another as well as other stuff i have not thought of yet 

I will then redo the same but for a bare metal setup not docker

 

 

 

Posted
8 hours ago, CassTG said:

And thought i would start work on an extended script which can be used by Newbies

Hey CassTG,

That sounds really cool. When you get finished maybe see if Emby devs will put up an article and pin it highlighting this solution minus all our gossip? Personally, I am not comfy with dockers yet, so I'll stick to the first script you made at least for now? Seems to me that the first script should be for normal packages and the second script your still working on should be only for docker? I mean you either need one or the other, right? Almost no one would need both scripts?

Anyway, I am going to modify your first script and take out the docker stuff for myself. If you want I can repost it when I get it done? Probably not since you were already planning a more complete "bare metal" script.

This has been really fun! I am so glad you took the time to do this!

Posted
8 hours ago, usTom said:

Hey CassTG,

That sounds really cool. When you get finished maybe see if Emby devs will put up an article and pin it highlighting this solution minus all our gossip? Personally, I am not comfy with dockers yet, so I'll stick to the first script you made at least for now? Seems to me that the first script should be for normal packages and the second script your still working on should be only for docker? I mean you either need one or the other, right? Almost no one would need both scripts?

Anyway, I am going to modify your first script and take out the docker stuff for myself. If you want I can repost it when I get it done? Probably not since you were already planning a more complete "bare metal" script.

This has been really fun! I am so glad you took the time to do this!

To be fair the permissions options in that script i posted yesterday is is for non docker installs as its rare you get those permission issues when using a docker setup as thats handled in the compose file, most people who suffer permission issues do so on bare metal installs, you can do what you like with the script, to be honest leaving them in does not matter as you wont be selecting that issue.

And i can tell you this, i was the same about docker not wanting to learn, seemed alien etc, but it's so easy to pick up it's untrue, and the benefit very few issues, and the great thing is muck a docker up, it takes 5 seconds to rebuild that docker, not so easy on baremetal. 

Posted
11 hours ago, CassTG said:

And i can tell you this, i was the same about docker not wanting to learn, seemed alien etc, but it's so easy to pick up it's untrue, and the benefit very few issues, and the great thing is muck a docker up, it takes 5 seconds to rebuild that docker, not so easy on baremetal. 

I'm sold on the benefits, my problem is that it's but another layer of abstraction and half the time I don't know what's going on with baremetal. And I might just use my PC for 3 months only to play games, and then maybe home renovate for several months with no computer use, then come back to relearn virtual machine, flatpak, and docker variations on computing is a bit intimidating.

I recently was successfully using Shinobi CCTV in a docker. But that program didn't meet my needs, so I was going to do the Zoneminder docker but that one is looking for someone to maintain it. Maybe that's something that would interest you? I don't think there's much to maintain there, I think it's a LAMP that is set up to talk to security cameras. Anyway, that's a good docker case for me because I don't like fighting mysql or apache2 settings to behave with mulitple locally hosted apps. I'm sure the same goes for Emby, but Emby is so darn polished and easy and well-behaved, I haven't ran into special reason to think of putting it into a docker (other than to solve the file permissions thing).

Another thing is I learn better visually, by seeing an example, so I've looked at quite a few docker videos but I haven't found a set that has even laid out where the files are kept and how things are structured. I haven't even seen someone going through the docker commands and options thoroughly. They mostly just follow steps you'd find on any app website that gives you the docker commands to get their docker working. If you know of some more thorough videos I'd be interested in checking them out.

Anyway, I don't mean to take up all your time. Just thought I'd let you know I appreciate the advice and help, but also let you know where I'm stuck at. Cheers!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...