Skip to content

Instantly share code, notes, and snippets.

@bpvarsity
Forked from gsj1377/app-installation.sh
Last active March 1, 2022 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpvarsity/5f001f8ae9889a8549cdfa64037a6ab5 to your computer and use it in GitHub Desktop.
Save bpvarsity/5f001f8ae9889a8549cdfa64037a6ab5 to your computer and use it in GitHub Desktop.
pulsedmedia ARR app installation script
#!/usr/bin/env bash
rm -rf $HOME/.bin
mkdir -p $HOME/.config/{jellyfin}
## change version no to update JELLYFINd
JELLYFIN_VERSION=$(curl -s 'https://repo.jellyfin.org/releases/server/linux/stable/combined/' | egrep -m 1 -o "jellyfin_[0-9\.]+_amd64\.tar\.gz" | head -n 1 | cut -d "_" -f2)
## to update ASPDOTNET find new url at https://dotnet.microsoft.com/en-us/download/dotnet/5.0
ASPDOTNET_URL="https://download.visualstudio.microsoft.com/download/pr/f56adf04-e4a8-48bf-b2e2-722e7206a4f2/7f40d4ebeff281120ba76e7b091356b0/aspnetcore-runtime-5.0.14-linux-x64.tar.gz"
random_open_port(){
LOW_BOUND=10000
UPPER_BOUND=65000
comm -23 <(seq ${LOW_BOUND} ${UPPER_BOUND} | sort -u) <(ss -Htan | awk '{print $4}' | rev | cut -d':' -f1 | rev | sort -u) | shuf | head -n 1
}
JELLYFIN_PORT=$(random_open_port)
USERNAME=$(whoami)
## kill tmux
kill -9 $(pgrep -f -u ${USERNAME} "tmux") > /dev/null 2>&1
## Jellyfin
## installing aspnetcore
app="aspnetcore"
echo ""
echo "downloading...${app^^}"
echo "to update find latest link from https://dotnet.microsoft.com/en-us/download/dotnet/5.0"
installdir="$HOME/.bin/dotnet"
mkdir -p ${installdir}
cd ${installdir}
wget $ASPDOTNET_URL > /dev/null 2>&1
tar -xvzf *.tar.gz > /dev/null 2>&1
rm *.tar.gz > /dev/null 2>&1
echo "export DOTNET_ROOT=$HOME/.bin/dotnet" >> $HOME/.bashrc
export DOTNET_ROOT=$HOME/.bin/dotnet
echo "Installation files downloaded and extracted"
echo "${app^^} Installed"
## installing jellyfin
app="jellyfin"
installdir="$HOME/.bin"
datadir="$HOME/.config/${app}"
cd ${installdir}
echo ""
echo "Downloading...${app^^}"
wget "https://repo.jellyfin.org/releases/server/portable/stable/combined/${app}_${JELLYFIN_VERSION}.tar.gz" -O ${app}.tar.gz> /dev/null 2>&1
mkdir ${app}
tar -xvzf ${app}.tar.gz -C ${app} --strip-components=2 > /dev/null 2>&1
rm ${app}.tar.gz > /dev/null 2>&1
echo "Installation files downloaded and extracted"
echo "${app^^} Installed"
echo "configuring ${app^^}"
if [ ! -f $datadir/network.xml ]; then
cat << EOF > $datadir/network.xml
<?xml version="1.0" encoding="utf-8"?>
<NetworkConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<EnableUPnP>false</EnableUPnP>
<PublicPort>8096</PublicPort>
<UPnPCreateHttpPortMap>false</UPnPCreateHttpPortMap>
<UDPPortRange />
<EnableIPV6>false</EnableIPV6>
<EnableIPV4>true</EnableIPV4>
<EnableSSDPTracing>false</EnableSSDPTracing>
<SSDPTracingFilter />
<UDPSendCount>2</UDPSendCount>
<UDPSendDelay>100</UDPSendDelay>
<IgnoreVirtualInterfaces>true</IgnoreVirtualInterfaces>
<VirtualInterfaceNames>vEthernet*</VirtualInterfaceNames>
<GatewayMonitorPeriod>60</GatewayMonitorPeriod>
<TrustAllIP6Interfaces>false</TrustAllIP6Interfaces>
<HDHomerunPortRange />
<PublishedServerUriBySubnet />
<AutoDiscoveryTracing>false</AutoDiscoveryTracing>
<AutoDiscovery>true</AutoDiscovery>
<PublicHttpsPort>8920</PublicHttpsPort>
<HttpServerPortNumber>8096</HttpServerPortNumber>
<HttpsPortNumber>8920</HttpsPortNumber>
<EnableHttps>false</EnableHttps>
<CertificatePath />
<CertificatePassword />
<EnableRemoteAccess>true</EnableRemoteAccess>
<BaseUrl />
<LocalNetworkSubnets />
<LocalNetworkAddresses />
<RequireHttps>false</RequireHttps>
<RemoteIPFilter />
<IsRemoteIPFilterBlacklist>false</IsRemoteIPFilterBlacklist>
<KnownProxies />
</NetworkConfiguration>
EOF
fi
sed -i -e "s/\(<PublicPort>\)[^<]*\(<\/PublicPort>\)/\1$JELLYFIN_PORT\2/g" $datadir/network.xml
sed -i -e "s/\(<HttpServerPortNumber>\)[^<]*\(<\/HttpServerPortNumber>\)/\1$JELLYFIN_PORT\2/g" $datadir/network.xml
sed -i -e "s/<BaseUrl \/>/<BaseUrl><\/BaseUrl>/" $datadir/network.xml
sed -i -e "s/\(<BaseUrl>\)[^<]*\(<\/BaseUrl>\)/\1\/public-${USERNAME}\/${app}\2/g" $datadir/network.xml
echo "${app^^} configured"
echo ""
cat << 'EOF' >> $HOME/.bashrc
alias jellyfin='tmux new-session -d -s "jellyfin" "export DOTNET_ROOT=$HOME/.bin/dotnet && export JELLYFIN_DATA_DIR=$HOME/.config/jellyfin && JELLYFIN_LOG_DIR=$HOME/.config/jellyfin/log && nice -n 19 sh -c $HOME/.bin/jellyfin/jellyfin"'
EOF
cat << EOF > $HOME/.lighttpd/custom
\$HTTP["url"] =~ "^/jellyfin($|/)" {
proxy.server = ( "" => ( (
"host" => "127.0.0.1",
"port" => $JELLYFIN_PORT
) ) ),
proxy.forwarded = (
"for" => 1,
"host" => 1,
"by" => 1
),
proxy.header = ( "map-urlpath" => (
"/jellyfin" => "/public-$USERNAME/jellyfin"
) )
}
EOF
source ~/.bashrc
echo ""
echo "starting applications"
tmux new-session -d -s "jellyfin" "export DOTNET_ROOT=$HOME/.bin/dotnet && export JELLYFIN_DATA_DIR=$HOME/.config/jellyfin && JELLYFIN_LOG_DIR=$HOME/.config/jellyfin/log && nice -n 19 sh -c $HOME/.bin/jellyfin/jellyfin"
echo ""
echo "connect to running application use command 'tmux attach -t <app-name>'"
echo "e.g to attach to radarr 'tmux attach -t radarr'"
echo "exit tmux session by pressing 'CTRL+b' then 'a' "
echo ""
echo "to start application manually use appname as commend"
echo "e.g for SONARR use 'sonarr'"
echo ""
echo "JELLYFIN-URL = https://$(hostname)/public-$USERNAME/jellyfin/web/index.html"
echo "JELLYFIN-ALTERNATE-URL" = $(curl -s ifconfig.me):$JELLYFIN_PORT/public-$USERNAME/jellyfin/
echo ""
echo "restarting lighttpd"
killall -9 -u $(whoami) lighttpd; killall -9 -u $(whoami) php-cgi
echo "it may take 1-2 minutes to restart lighttpd"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment