Last active
September 8, 2023 13:01
-
-
Save atiris/34dc670264274b3a472f2a718e4de83a to your computer and use it in GitHub Desktop.
Wizard to install the current version of JDownloader (jdownloader.org) on raspberry pi (running osmc or another linux). You can install (together or individually) latest java for RPI, download and install headless JDownloader (my.jdownloader.org) and create service to start JDownloader after boot and restart automatically after crash.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script: osmc-java-jdownloader-installer.sh | |
# Author: Jozef Pažin | |
# Description: Wizard to install the current version of java and/or jdownloader on raspberry pi running osmc. | |
# License: MIT | use arbitrarily, attribution is not required | |
# How to run: | |
# - Check if this code is correct first because this script need to be run under root and run gist | |
# from web is not recommended in terms of security only that you know exactly what it does. Check it: | |
# curl -Ls https://gist.github.com/atiris/34dc670264274b3a472f2a718e4de83a/raw | nano - | |
# - And then run it with command (this way support 'read' user inputs): | |
# | |
# SCRIPT=`curl -Ls https://gist.github.com/atiris/34dc670264274b3a472f2a718e4de83a/raw`; sudo bash -c "$SCRIPT" | |
# | |
# Inspiration: | |
# - https://gist.github.com/ribasco/fff7d30b31807eb02b32bcf35164f11f | |
# - https://github.com/PlusMinus0/headless-jd2-docker | |
# - https://gist.github.com/leosuncin/50367b3c905fe8699b13bd85ad26071b | |
if [[ "$EUID" -ne 0 ]]; then | |
echo "" | |
echo "Please login as root: sudo su" | |
echo "" | |
return | |
fi | |
RUN_AS_USER=root | |
# Colors | |
NC='\033[0m' | |
RED='\033[0;91m' | |
GREEN='\033[0;92m' | |
BLUE='\033[0;94m' | |
YELLOW='\033[0;93m' | |
echo "" | |
# Java | |
JAVA_VERSION_LOCAL=`echo $(java -version 2>&1)| awk -F \" '{print $2}'` | |
if [[ $JAVA_VERSION_LOCAL = *[!\ ]* ]]; then | |
echo -e "Local java version is ""$RED""$JAVA_VERSION_LOCAL""$NC" | |
response=n | |
echo "" | |
echo -e "$RED""Install java anyway?""$NC" | |
read -p "[y/N] " response | |
response=${response,,} | |
else | |
echo -e "$YELLOW""Java is not installed.""$GREEN"" I will run the installation for you.""$NC" | |
response=y | |
fi | |
if [[ $response =~ ^(yes|y) ]]; then | |
# original java first | |
echo "-----BEGIN PGP PUBLIC KEY BLOCK----- | |
Version: SKS 1.1.5 | |
Comment: Hostname: keyserver.ubuntu.com | |
mI0ES9/P3AEEAPbI+9BwCbJucuC78iUeOPKl/HjAXGV49FGat0PcwfDd69MVp6zUtIMbLgkU | |
OxIlhiEkDmlYkwWVS8qy276hNg9YKZP37ut5+GPObuS6ZWLpwwNus5PhLvqeGawVJ/obu7d7 | |
gM8mBWTgvk0ErnZDaqaU2OZtHataxbdeW8qH/9FJABEBAAG0DUxhdW5jaHBhZCBWTEOImwQQ | |
AQIABgUCVsN4HQAKCRAEC6TrO3+B2tJkA/jM3b7OysTwptY7P75sOnIu+nXLPlzvja7qH7Wn | |
A23itdSker6JmyJrlQeQZu7b9x2nFeskNYlnhCp9mUGu/kbAKOx246pBtlaipkZdGmL4qXBi | |
+bi6+5Rw2AGgKndhXdEjMxx6aDPq3dftFXS68HyBM3HFSJlf7SmMeJCkhNRwiLYEEwECACAF | |
Akvfz9wCGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAAKCRDCUYJI7qFIhucGBADQnY4V1xKT | |
1Gz+3ERly+nBb61BSqRx6KUgvTSEPasSVZVCtjY5MwghYU8T0h1PCx2qSir4nt3vpZL1luW2 | |
xTdyLkFCrbbIAZEHtmjXRgQu3VUcSkgHMdn46j/7N9qtZUcXQ0TOsZUJRANY/eHsBvUg1cBm | |
3RnCeN4C8QZrir1CeA== | |
=CziK | |
-----END PGP PUBLIC KEY BLOCK-----" > temporarykey.txt | |
apt-key add temporarykey.txt | |
rm -f temporarykey.txt | |
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections | |
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections | |
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list | |
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list | |
echo -e "$NC""Remove source with: rm /etc/apt/sources.list.d/webupd8team-java.list" | |
apt update | |
apt install -f | |
dpkg --configure -a | |
apt install -y oracle-java8-installer | |
apt install -y oracle-java8-set-default | |
echo "" | |
echo -e "$GREEN""Java installation script is complete... Testing.""$NC" | |
JAVA_VERSION_LOCAL=`echo $(java -version 2>&1)| awk -F \" '{print $2}'` | |
if [[ $JAVA_VERSION_LOCAL = *[!\ ]* ]]; then | |
echo "Actual java vesion on your system is:" | |
java -version | |
else | |
# alternative java installer | |
echo -e "$RED""First attempt failed! I am trying to install the openjdk version...""$NC" | |
apt install -y openjdk-8-jdk | |
echo -e "$GREEN""Java installation script is complete, again... Testing.""$NC" | |
fi | |
else | |
echo "Java installation skipped." | |
fi | |
JAVA_VERSION_LOCAL=`echo $(java -version 2>&1)| awk -F \" '{print $2}'` | |
if [[ $JAVA_VERSION_LOCAL = *[!\ ]* ]]; then | |
echo "Actual java vesion on your system is:" | |
java -version | |
else | |
echo -e "$RED""Java is still not installed!""$NC" | |
echo "There is probably a new version of java and the installer wasn't yet updated to reference it." | |
echo -e "$GREEN""You can do this steps to install java manually:""$NC" | |
echo "" | |
echo "Check if your system supports openjdk alternative and use it." | |
echo "" | |
echo "Or harder way:" | |
echo "Open oracle download site https://www.oracle.com/technetwork/java/javase/downloads/index.html" | |
echo "Find Java SE 8 link, accept license and select jdk-8uXXX-linux-arm32-vfp-hflt.tar.gz version" | |
echo "Download it (version 8 is not supported, so you need to have an oracle account)" | |
echo "to any directory and unpack with command:" | |
echo -e "$BLUE""tar -xzf jdk-8uXXX-linux-arm32-vfp-hflt.tar.gz""$NC" | |
echo "Create /usr/local/java directory mkdir -p -v /usr/local/java" | |
echo "Move unpacked to /usr/local/java/jdk1.8.0_XXX:" | |
echo -e "$BLUE""mv /path/to/jdk1.8.0_XXX /usr/local/java/jdk1.8.0_XXX""$NC" | |
echo "Update java alternatives with new path:" | |
echo -e "$BLUE""sudo update-alternatives --install \"/usr/bin/java\" \"java\" \"/usr/local/java/jdk1.8.0_XXX/bin/java\" 1""$NC" | |
echo "Set default java with:" | |
echo -e "$BLUE""sudo update-alternatives --set java /usr/local/java/jdk1.8.0_XXX/bin/java""$NC" | |
response=n | |
echo "" | |
echo -e "$RED""Continue anyway?""$NC" | |
read -p "[y/N] " response | |
response=${response,,} | |
if [[ $response =~ ^(no|n) ]]; then | |
exit 0 | |
fi | |
fi | |
echo "" | |
# JDownloader | |
if [ -e /opt/JDownloader/JDownloader.jar ]; then | |
FILE_DATE=$(date -r /opt/JDownloader/JDownloader.jar +%Y-%m-%d) | |
echo -e "JDownloader already installed. File date is ""$RED""$FILE_DATE""$NC""." | |
echo "" | |
response=n | |
echo -e "$RED""Remove it and install actual JDownloader anyway?""$NC" | |
read -p "[y/N] " response | |
response=${response,,} | |
else | |
echo -e "$YELLOW""JDownloader is not installed.""$GREEN"" Let me run it.""$NC" | |
response=y | |
fi | |
if [[ $response =~ ^(yes|y) ]]; then | |
echo -e "$BLUE" | |
echo "I'll download JDownloader from official site jdownloader.org." | |
echo "Then I will run the installation process several times, until JDownloader" | |
echo "ask you for login and password. Please press \"y\" at that time, and set" | |
echo "your credentials from my.jdownloader.org (you must first be registered)." | |
echo "Then wait some time (few seconds) until JDownloader save this settings" | |
echo "and interrupt JDownloader installation by pressing \"CTRL+C\"." | |
echo "You can continue in next step with installation of daemon," | |
echo "to start JDownloader automatically on reboot or after crash." | |
echo -e "$NC" | |
echo "Press enter to continue" | |
read | |
echo -e "$GREEN""OK""$NC" | |
echo "" | |
if [[ "$RUN_AS_USER" == 'root' ]] && [[ `id -u osmc 2>/dev/null || echo -1` -ge 0 ]]; then | |
echo "Install JDownloader with 'osmc' user rights." | |
RUN_AS_USER=osmc | |
fi | |
if [[ "$RUN_AS_USER" == 'root' ]] && [[ `id -u pi 2>/dev/null || echo -1` -ge 0 ]]; then | |
echo "Install JDownloader with 'pi' user rights." | |
RUN_AS_USER=pi | |
fi | |
if [ "$RUN_AS_USER" == 'root' ]; then | |
echo "Installing as 'root'?" | |
echo "Running JDownloader under 'root' user is not recommended." | |
response=xxxundefinedxxx | |
echo "" | |
echo -e "$RED""Can you type another user name?""$NC" | |
read -p "Username " response | |
response=${response,,} | |
if [[ $response =~ ^(xxxundefinedxxx) ]]; then | |
echo "Well, ok then, I'll use 'root' for JDownloader." | |
else | |
echo "JDownloader will be run with $response rights." | |
RUN_AS_USER=$response | |
fi | |
fi | |
if [ ! -d /opt/JDownloader ]; then | |
mkdir -p /opt/JDownloader | |
echo "Folder /opt/JDownloader created." | |
else | |
rm -rf /opt/JDownloader/* | |
echo "Folder for JDownloader cleaned." | |
fi | |
chown -fR $RUN_AS_USER:users /opt/JDownloader | |
sudo -u $RUN_AS_USER wget -O /opt/JDownloader/JDownloader.jar --progress=bar:force http://installer.jdownloader.org/JDownloader.jar | |
echo -e "$BLUE""Starting JDownloader installation." | |
echo "Wait for the login / password request." | |
echo "Register here: https://my.jdownloader.org/" | |
echo -e "$NC" | |
doNextLoop=1 | |
while [ $doNextLoop -eq 1 ] | |
do | |
doNextLoop=0 | |
sudo -u $RUN_AS_USER java -jar /opt/JDownloader/JDownloader.jar -norestart | |
echo -e "$RED""You have already seen a request to enter your login information?""$NC" | |
read -p "[y/N] " response | |
response=${response,,} | |
if [[ $response =~ ^(no|n| ) ]] || [[ -z $response ]]; then | |
doNextLoop=1 | |
fi | |
done | |
echo -e "$GREEN""JDownloader instalation is complete.""$NC" | |
echo "" | |
echo -e "$GREEN""Note about download youtube videos""$NC" | |
echo "" | |
echo "To download youtube videos you need to install ffmpeg" | |
echo "You can build it yourself or use static build. For static build:" | |
echo "Download armhf version from johnvansickle.com/ffmpeg" | |
echo -e "$BLUE""wget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-armhf-static.tar.xz""$NC" | |
echo "Extract it anywhere" | |
echo -e "$BLUE""tar -xvf ffmpeg-release-armhf-static.tar.xz""$NC" | |
echo "And set 2 paths to ffmpeg binaries in advanced settings of selected jDownloader" | |
echo "You can use my.jdownloader for this, go to settings, advanced and search for 'ffmpeg path'" | |
else | |
echo "JDownloader installation skipped." | |
fi | |
echo "" | |
# Service systemd jdownloader | |
if [ -e /etc/systemd/system/jdownloader.service ]; then | |
FILE_DATE=$(date -r /etc/systemd/system/jdownloader.service +%Y-%m-%d) | |
echo -e "Service jdownloader already exists. File date is ""$RED""$FILE_DATE""$NC""." | |
echo "" | |
response=n | |
echo -e "$RED""Replace existing with default service implementation?""$NC" | |
read -p "[y/N] " response | |
response=${response,,} | |
else | |
echo -e "$YELLOW""Service for jdownloader not exists yet.""$GREEN"" No worries, I will create it.""$NC" | |
response=y | |
fi | |
if [[ $response =~ ^(yes|y) ]]; then | |
echo "" | |
touch /opt/JDownloader/JDownloader.pid | |
if [[ "$RUN_AS_USER" == 'root' ]] && [[ `id -u osmc 2>/dev/null || echo -1` -ge 0 ]]; then | |
echo "Using 'osmc' user rights." | |
RUN_AS_USER=osmc | |
fi | |
if [[ "$RUN_AS_USER" == 'root' ]] && [[ `id -u pi 2>/dev/null || echo -1` -ge 0 ]]; then | |
echo "Using 'pi' user rights." | |
RUN_AS_USER=pi | |
fi | |
if [ "$RUN_AS_USER" == 'root' ]; then | |
echo "You want to start the service as 'root' user?" | |
echo "Running JDownloader under 'root' user is not recommended." | |
response=xxxundefinedxxx | |
echo "" | |
echo -e "$RED""Can you type another user name?""$NC" | |
read -p "Username " response | |
response=${response,,} | |
if [[ $response =~ ^(xxxundefinedxxx) ]]; then | |
echo "Well, ok then, I'll use 'root' for JDownloader service." | |
else | |
echo "JDownloader will be run with $response rights." | |
RUN_AS_USER=$response | |
fi | |
fi | |
echo "[Unit] | |
Description=JDownloader2 headless service | |
After=network.target | |
[Service] | |
# User=""$RUN_AS_USER"" # not all jDownloader services working with non root user | |
Type=simple | |
Environment=JD_HOME=/opt/JDownloader | |
WorkingDirectory=/opt/JDownloader | |
ExecStart=/usr/bin/java -Djava.awt.headless=true -jar /opt/JDownloader/JDownloader.jar | |
RemainAfterExit=yes | |
Restart=on-failure | |
RestartSec=10s | |
[Install] | |
WantedBy=multi-user.target | |
" > /etc/systemd/system/jdownloader.service | |
if [ -e /etc/systemd/system/jdownloader.service ]; then | |
systemctl daemon-reload | |
echo -e "Service /etc/systemd/user/jdownloader.service > ""$GREEN""created OK""$NC" | |
systemctl enable jdownloader | |
echo -e "Service jdownloader enabled > ""$GREEN""OK""$NC" | |
systemctl start jdownloader | |
SERVICE_STATE=$(ps -ef | grep -v grep | grep JDownloader | wc -l) | |
if [ "$SERVICE_STATE" -eq 0 ]; then | |
echo -e "$RED""WARNING! Service jdownloader is down.""$NC" | |
else | |
echo -e "Service jdownloader started > ""$GREEN""OK""$NC" | |
fi | |
echo "" | |
echo -e "$GREEN""Service installation is complete.""$NC" | |
echo "You can check service status with: systemctl status jdownloader" | |
echo "Sometimes jDownloader create file or directory with root owner rights" | |
echo "To fix it you can crate cron job:" | |
echo "sudo crontab -u root -e" | |
echo "And run chow for your user (osmc) on your requested directory like this:" | |
echo "*/5 * * * * sudo chown -R osmc:osmc /home/osmc/Download >/dev/null 2>&1" | |
else | |
echo -e "$RED""ERROR! I can not create a service.""$NC" | |
fi | |
else | |
echo "Service installation skipped." | |
fi | |
echo "" | |
# Final message | |
echo -e "$GREEN""That's all, I hope everything works for you.""$NC" | |
echo -e "$GREEN""Now you can check JDownloader on https://my.jdownloader.org/""$NC" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great script worked like a charm!!!
Thanks for the contribution!