Skip to content

Commit

Permalink
Code cleanup/tv (#8189)
Browse files Browse the repository at this point in the history
* Cleanup tv.py

Remove code in comments
Remove comments explained by loggers
Fix most broad Exception clause

* Update debiab-ubuntu-installer.sh and init.systemd to use a pip install
TODO: Update remaining init.ubuntu, init.debian, init.upstart

* Add skeleton for testing web api calls, needs flesh

Signed-off-by: miigotu <miigotu@gmail.com>
Co-authored-by: pigsyn <soulard.morgan@gmail.com>
  • Loading branch information
miigotu and pigsyn committed Sep 22, 2022
1 parent 913d0b9 commit f772dff
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 151 deletions.
187 changes: 132 additions & 55 deletions contrib/debian-ubuntu-install.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash --
# Author: @DirtyCajunRice

LOCATION=/opt/sickchill

# Check if ran by root
if [[ $UID -ne 0 ]]; then
echo 'Script must be run as root'
Expand Down Expand Up @@ -30,7 +32,7 @@ internal_ip=$(ip r g 8.8.8.8 | awk 'NR==1{print $7};')
apt-get -qq install whiptail -y

function check_packages {
packages=$(dpkg -l unrar git-core openssl libssl-dev python3.8 2>&1 | grep "no packages" | awk '{ print $6 }' | tr '\n' ' ')
packages=$(dpkg -l unrar openssl libssl-dev python3 2>&1 | grep "dpkg-query" | awk '{ print $NF }' | tr '\n' ' ')
}

# Check to see what SickChill Dependencies are missing
Expand All @@ -56,77 +58,151 @@ ${packages}
Please resolve these issues and restart the install script" 15 66
exit 1
fi
echo "done"

# Check to see if sickchill exists; If not make user/group
if [[ ! "$(getent group sickchill)" ]]; then
echo "Adding SickChill Group"
addgroup --system sickchill
if ! addgroup --system sickchill; then
whiptail --title "Failed to create sickchill user" --msgbox "Failed to create sickchill user" 8 128
exit 1
fi
fi

if [[ ! "$(getent passwd sickchill)" ]]; then
echo "Adding SickChill User"
adduser --disabled-password --system --home /var/lib/sickchill --gecos "SickChill" --ingroup sickchill sickchill
if ! adduser --disabled-password --system --home /var/lib/sickchill --gecos "SickChill" --ingroup sickchill sickchill; then
whiptail --title "Failed to disable password for sickchill user" --msgbox "Failed to disable password for sickchill user" 8 128
exit 1
fi
fi

# Check to see if /opt/sickchill exists. If it does ask if they want to overwrite it. if they do not exit 1
# if they do, remove the whole directory and recreate
if [[ ! -d /opt/sickchill ]]; then
echo "Creating New SickChill Folder"
mkdir /opt/sickchill && chown sickchill:sickchill /opt/sickchill
echo "Git Cloning In Progress"
su -c "cd /opt && git clone -q https://github.com/SickChill/SickChill.git /opt/sickchill" -s /bin/bash sickchill
if [[ ${SUDO_USER} != "root" ]]; then
username=${SUDO_USER}
else
whiptail --title 'Overwrite?' --yesno "/opt/sickchill already exists, do you want to overwrite it?" 8 40
choice=$?
if [[ ${choice} == 0 ]]; then
echo "Removing Old SickChill Folder And Creating New SickChill Folder"
rm -rf /opt/sickchill && mkdir /opt/sickchill && chown sickchill:sickchill /opt/sickchill
echo "Git Cloning In Progress"
su -c "cd /opt && git clone -q https://github.com/SickChill/SickChill.git /opt/sickchill" -s /bin/bash sickchill
else
echo
username=
fi

username=$(whiptail --title 'Add user to group group?' --inputbox "Do you want to add a user to the sickchill group?" --ok-button "Add" --cancel-button "Skip" 8 128 "${username}" 3>&1 1>&2 2>&3)
if [[ ${#username} -gt 0 ]]; then
echo "Adding $username to the sickchill group"
if ! sudo usermod -a -G sickchill "$username"; then
whiptail --title "Failed to add user to group" --msgbox "Failed to add $username to the sickchill group" 8 128
exit 1
fi
fi

# Depending on Distro, cp the service script, then change the owner/group and change the permissions. Finally
# start the service
if [[ ${distro} == ubuntu ]]; then
if [[ $(/sbin/init --version 2>/dev/null) =~ upstart ]]; then
echo "Copying Startup Script To Upstart"
cp /opt/sickchill/contrib/runscripts/init.upstart /etc/init/sickchill.conf
chown root:root /etc/init/sickchill.conf && chmod 644 /etc/init/sickchill.conf
echo "Starting SickChill"
service sickchill start

elif [[ $(systemctl) =~ -\.mount ]]; then
echo "Copying Startup Script To systemd"
cp /opt/sickchill/contrib/runscripts/init.systemd /etc/systemd/system/sickchill.service
chown root:root /etc/systemd/system/sickchill.service && chmod 644 /etc/systemd/system/sickchill.service
echo "Starting SickChill"
systemctl -q enable sickchill && systemctl -q start sickchill
if [[ -d ${LOCATION} ]]; then
if whiptail --title 'Rename?' --yesno "${LOCATION} already exists, do you want to rename it? If not, we will exit and you can fix the issues and re-run this script" 8 140;
then
echo "Renaming old SickChill Folder to ${LOCATION}.old"
if ! mv ${LOCATION} ${LOCATION}.old; then
whiptail --title "Failed to rename ${LOCATION}" --msgbox "Failed to rename ${LOCATION} to ${LOCATION}.old" 8 128
exit 1
fi
else
echo "Copying Startup Script To init"
cp /opt/sickchill/contrib/runscripts/init.ubuntu /etc/init.d/sickchill
chown root:root /etc/init.d/sickchill && chmod 644 /etc/init.d/sickchill
echo "Starting SickChill"
update-rc.d sickchill defaults && service sickchill start
echo "Please fix the issues and re-run this script"
exit 1
fi
elif [[ ${distro} == debian ]]; then
if [[ $(systemctl) =~ -\.mount ]]; then
echo "Copying Startup Script To systemd"
cp /opt/sickchill/contrib/runscripts/init.systemd /etc/systemd/system/sickchill.service
chown root:root /etc/systemd/system/sickchill.service && chmod 644 /etc/systemd/system/sickchill.service
echo "Starting SickChill"
systemctl -q enable sickchill && systemctl -q start sickchill
else
echo "Copying Startup Script To init"
cp /opt/sickchill/contrib/runscripts/init.debian /etc/init.d/sickchill
chown root:root /etc/init.d/sickchill && chmod 755 /etc/init.d/sickchill
echo "Starting SickChill"
update-rc.d sickchill defaults && service sickchill start
fi

if [[ ! -d ${LOCATION} ]]; then
echo "Creating SickChill Folder"
if ! mkdir -p ${LOCATION}; then
whiptail --title "Failed to create ${LOCATION}" --msgbox "Failed to create ${LOCATION}" 8 128
exit 1
fi
if ! chown -R sickchill:sickchill ${LOCATION}; then
whiptail --title "Failed to change ownership of ${LOCATION}" --msgbox "Failed to change ownership of ${LOCATION}" 8 128
exit 1
fi
fi

echo "Creating virtual environment"
if ! sudo -u sickchill -g sickchill python3 -m venv ${LOCATION}; then
whiptail --title "Failed to create virtual environment" --msgbox "Failed to create virtual environment" 8 128
exit 1
fi

OS_NAME=$(grep -oP "(?:^ID=)(.*)" < /etc/os-release | sed 's|ID=||')
echo "Checking if we should add an index for your platform OS: ${OS_NAME}"
INDEXES=()

case "$OS_NAME" in
ubuntu)
INDEXES+=("--find-links=https://wheel-index.linuxserver.io/ubuntu/");;
alpine)
INDEXES+=("--find-links=https://wheel-index.linuxserver.io/alpine/")
INDEXES+=("--extra-index-url=https://alpine-wheels.github.io/index");;
raspbian|osmc)
INDEXES+=("--extra-index-url=https://www.piwheels.org/simple");;
*)
echo "No extra indexes needed that we know of";;
esac

WHEELS=("pip" "setuptools" "wheel")
echo "Installing" "${WHEELS[@]}"
if ! sudo -u sickchill -g sickchill ${LOCATION}/bin/pip install -U "${WHEELS[@]}" "${INDEXES[@]}"; then
whiptail --title "Failed to update pip" --msgbox "Failed to update pip" 8 128
exit 1
fi

WHEELS=("sickchill")
echo "Installing SickChill"
if ! sudo -u sickchill -g sickchill ${LOCATION}/bin/pip install -U "${WHEELS[@]}" "${INDEXES[@]}"; then
whiptail --title "Failed to install SickChill" --msgbox "Failed to install SickChill" 8 128
exit 1
fi

function download_service_file() {
export SERVICE_FILE=${2}
if ! curl https://raw.githubusercontent.com/SickChill/SickChill/master/contrib/runscripts/"$1" > "$2"; then
whiptail --title "Failed to download ${1}" --msgbox "Failed to download ${1}" 8 128
exit 1
fi

if ! chown root:root "$2" && chmod "$3" "$2"; then
whiptail --title "Failed to set permissions on ${2}" --msgbox "Failed to set permissions on ${2}" 8 128
exit 1
fi
}
# Depending on Distro, cp the service script, then change the owner/group and change the permissions. Finally
# start the service
if [[ $(/sbin/init --version 2>/dev/null) =~ upstart ]]; then
echo "Copying Startup Script To Upstart"
download_service_file "init.upstart" "/etc/init/sickchill.conf" "644"
echo "Starting SickChill"
service sickchill start
elif [[ $(systemctl) =~ -\.mount ]]; then
echo "Copying Startup Script To systemd"
download_service_file "init.systemd" "/etc/systemd/system/sickchill.service" "644"
echo "Starting SickChill"
systemctl -q enable sickchill && systemctl -q start sickchill
else
echo "Copying Startup Script To init"
download_service_file "init.${distro}" "/etc/init.d/sickchill" "755"
echo "Starting SickChill"
update-rc.d sickchill defaults && service sickchill start
fi

SERVICE_RESULT=$?

echo "If you run sickchill as the sickchill user like this:"
echo ">> sudo -u sickchill -g sickchill PATH= /opt/sickchill/bin/SickChill"
echo "Your config.ini and database will be in '/var/lib/sickchill/.config/sickchill/"
echo "If you run sickchill as the sickchill user like this:"
echo ">> PATH= /opt/sickchill/bin/SickChill"
echo "Your config.ini and database will be in '/home/${SUDO_USER}/.config/sickchill/"
echo "If you run sickchill as the sickchill user like this:"
echo ">> PATH= /opt/sickchill/bin/SickChill --datadir=/opt/sickchill"
echo "Your config.ini and database will be in '/opt/sickchill'"
echo "It is recommended to run sickchill as the sickchill user, as in the first example"
echo "To update sickchill, run the following command:"
echo ">> sudo -u sickchill -g sickchill ${LOCATION}/bin/pip install -U sickchill"

if [[ $SERVICE_RESULT != 0 ]]; then
whiptail --title "Failed to start SickChill" --msgbox "Failed to start SickChill, edit your service file at ${SERVICE_FILE}" 8 128
echo "Failed to start SickChill, edit your service file at ${SERVICE_FILE}"
exit 1
fi

# Finish by explaining the script is finished and give them the relevant IP addresses
Expand All @@ -137,4 +213,5 @@ whiptail --title Complete --msgbox \
OR
External IP: http://$external_ip:8081
make sure to add sickchill to your download clients group" 15 66
make sure to add sickchill to your download clients group
and check the log above for information about running sickchill" 15 66
2 changes: 1 addition & 1 deletion contrib/runscripts/init.systemd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Group=sickchill

Type=forking
GuessMainPID=no
ExecStart=/usr/bin/python3 /opt/sickchill/SickChill.py -q --daemon --nolaunch --datadir=/opt/sickchill
ExecStart=/opt/sickchill/bin/SickChill -q --daemon --nolaunch

[Install]
WantedBy=multi-user.target
4 changes: 2 additions & 2 deletions sickchill/oldbeard/show_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def run(self):
self._finish_early()
return

self.show.load_imdb_imfo()
self.show.load_imdb_info()

try:
self.show.saveToDB()
Expand Down Expand Up @@ -661,7 +661,7 @@ def run(self):
self.finish()
return

self.show.load_imdb_imfo()
self.show.load_imdb_info()

# have to save show before reading episodes from db
try:
Expand Down
Loading

0 comments on commit f772dff

Please sign in to comment.