Skip to content

Commit

Permalink
/plex_autoscan
Browse files Browse the repository at this point in the history
use the right folder now
  • Loading branch information
MrDoobPG authored and MrDoobPG committed Nov 21, 2019
1 parent 1ee6e34 commit d17ead7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 37 deletions.
27 changes: 15 additions & 12 deletions menu/pgscan/pgscan.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# KEY VARIABLE RECALL & EXECUTION
mkdir -p /var/plexguide/pgscan
mkdir -p /opt/appdata/pgscan

touch /var/plexguide/pgscan/plex.token
touch /var/plexguide/pgscan/plex.pw
touch /var/plexguide/pgscan/plex.user
# FUNCTIONS START ##############################################################
# FIRST FUNCTION
variable() {
Expand All @@ -16,15 +17,16 @@ deploycheck() {
else dstatus="⚠️ NOT DEPLOYED"; fi
}
userstatus() {
userdep=$(cat /var/plexguide/plex.pw)
userdep=$(cat /var/plexguide/pgscan/plex.pw)
if [ "$userdep" != "" ]; then
ustatus="✅ DEPLOYED"
else ustatus="⚠️ NOT DEPLOYED"; fi
}
tokenstatus() {
ptokendep=$(cat /var/plexguide/plex.token)
touch $ptokendep
ptokendep=$(cat /var/plexguide/pgscan/plex.token)
if [ "$ptokendep" != "" ]; then
PGSELFTEST=$(curl -LI "http://localhost:32400/system?X-Plex-Token=$(cat /opt/plex_autoscan/config/config.json | jq .PLEX_TOKEN | sed 's/"//g' )" -o /dev/null -w '%{http_code}\n' -s)
PGSELFTEST=$(curl -LI "http://localhost:32400/system?X-Plex-Token=$(cat /opt/plex_autoscan/config/config.json | jq .PLEX_TOKEN | sed 's/"//g')" -o /dev/null -w '%{http_code}\n' -s)
if [[ $PGSELFTEST -ge 200 && $PGSELFTEST -le 299 ]]; then
pstatus="✅ DEPLOYED"
else
Expand All @@ -50,18 +52,19 @@ EOF
}

user() {
touch /var/plexguide/plex.pw
user=$(cat /var/plexguide/plex.pw)
touch /var/plexguide/pgscan/plex.pw
user=$(cat /var/plexguide/pgscan/plex.pw)
if [ "$user" == "" ]; then
bash /opt/plexguide/menu/pgscan/scripts/plex_pw.sh
fi
}
token() {
touch /opt/appdata/pgscan/plex.token
ptoken=$(cat /opt/appdata/pgscan/plex.token)
touch /var/plexguide/pgscan/plex.token
ptoken=$(cat /var/plexguide/pgscan/plex.token)
if [ "$ptoken" == "" ]; then
bash /opt/plexguide/menu/pgscan/scripts/plex_token.sh
ptoken=$(cat /opt/appdata/pgscan/plex.token)
bash /opt/plexguide/menu/pgscan/scripts/plex_token.sh 1>/dev/null 2>&1
sleep 2
ptoken=$(cat /var/plexguide/pgscan/plex.token)
if [ "$ptoken" == "" ]; then
tee <<-EOF
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -178,7 +181,7 @@ deploycheck
NOTE : Plex_AutoScan are located in /opt/plex_autoscan
[1] Deploy Plex Username & Plex Passwort [ $ustatus ]
[1] Deploy Plex Username & Plex Password [ $ustatus ]
[2] Deploy Plex Token [ $pstatus ]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down
12 changes: 6 additions & 6 deletions menu/pgscan/scripts/plex_pw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ EOF
sleep 3
question 2

pw=$(cat /var/plexguide/plex.pw)
user=$(cat /var/plexguide/plex.user)
pw=$(cat /var/plexguide/pgscan/plex.pw)
user=$(cat /var/plexguide/pgscan/plex.user)

elif [[ "$typed" == "Z" || "$typed" == "z" ]]; then
exit
Expand Down Expand Up @@ -113,10 +113,10 @@ EOF
}

question3() {
echo "$pw" >/var/plexguide/plex.pw
echo "$user" >/var/plexguide/plex.user
ansible-playbook /opt/plexguide/menu/plex/token.yml
token=$(cat /var/plexguide/plex.token)
echo "$pw" >/var/plexguide/pgscan/plex.pw
echo "$user" >/var/plexguide/pgscan/plex.user
bash /opt/plexguide/menu/pgscan/scripts/plex_token.sh
token=$(cat /var/plexguide/pgscan/plex.token)
if [ "$token" != "" ]; then
tee <<-EOF
Expand Down
16 changes: 4 additions & 12 deletions menu/pgscan/scripts/plex_token.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
templatebackup=/opt/plexguide/menu/roles/plex_autoscan/templates/config.backup
template=/opt/plexguide/menu/roles/plex_autoscan/templates/config.json.j2

PLEX_LOGIN=$(cat /var/plexguide/plex.user)
PLEX_PASSWORD=$(cat /var/plexguide/plex.pw)
PLEX_LOGIN=$(cat /var/plexguide/pgscan/plex.user)
PLEX_PASSWORD=$(cat /var/plexguide/pgscan/plex.pw)

curl -qu "${PLEX_LOGIN}":"${PLEX_PASSWORD}" 'https://plex.tv/users/sign_in.xml' \
-X POST -H 'X-Plex-Device-Name: PlexMediaServer' \
Expand All @@ -30,15 +30,7 @@ if [ -z "$X_PLEX_TOKEN" ]; then
exit 1
fi
cp -r $template $templatebackup
echo $X_PLEX_TOKEN >/var/plexguide/plex.token
echo $X_PLEX_TOKEN >/var/plexguide/pgscan/plex.token

RAN=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
echo $RAN >/var/plexguide/pgscan.serverpass


# #sed -i 's/plex_auth_token/'$X_PLEX_TOKEN'/g' $template
# #use jq instead.
# jq '.PLEX_TOKEN = "$X_PLEX_TOKEN"' $template | sponge $template
# #sed -i 's/plex_autoscan_server_pass/'$RAN'/g' $template
# #use jq instead
# jq '.SERVER_PASS = "$RAN"' $template | sponge $template
echo $RAN >/var/plexguide/pgscan/pgscan.serverpass
8 changes: 4 additions & 4 deletions menu/roles/plex_autoscan/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
#########################################################################
---
- name: Set plex.user fact | username
shell: 'cat /var/plexguide/plex.user'
shell: 'cat /var/plexguide/pgscan/plex.user'
register: plexuser

- name: Set plex.user fact | passwort
shell: 'cat /var/plexguide/plex.pw'
shell: 'cat /var/plexguide/pgscan/plex.pw'
register: plexpass

- name: Set plex.user fact | token
shell: 'cat /var/plexguide/plex.token'
shell: 'cat /var/plexguide/pgscan/plex.token'
register: plex_auth_token

- name: Register IP
shell: 'cat /var/plexguide/server.ip'
register: ipaddress

- name: Register ServerPass
shell: 'cat /var/plexguide/pgscan.serverpass'
shell: 'cat /var/plexguide/pgscan/pgscan.serverpass'
register: plex_autoscan_server_pass

- name: Display Plex Auth Token
Expand Down
6 changes: 3 additions & 3 deletions menu/roles/plex_autoscan/tasks/subtasks/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
force: yes

- name: Token Recall
shell: 'cat /var/plexguide/plex.token'
shell: 'cat /var/plexguide/pgscan/plex.token'
register: plex_auth_token

- name: Register IP
shell: 'cat /var/plexguide/server.ip'
shell: 'cat /var/plexguide/pgscan/server.ip'
register: ipaddress

- name: plex_auto_scan server pass
shell: 'cat /var/plexguide/pgscan.serverpass'
shell: 'cat /var/plexguide/pgscan/pgscan.serverpass'
register: plex_autoscan_server_pass

when: not plex_autoscan_config.stat.exists
Expand Down

0 comments on commit d17ead7

Please sign in to comment.