Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mango #336

Merged
merged 50 commits into from
Aug 12, 2020
Merged

Mango #336

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
848e04a
Ensure only the full definition of the key is being retrieved
flying-sausages May 1, 2020
036b58d
Merge branch 'master' of github.com-fs:flying-sausages/swizzin
flying-sausages May 1, 2020
f428bd4
Merge branch 'master' of github.com-fs:flying-sausages/swizzin
flying-sausages May 3, 2020
560b0b7
Merge branch 'master' of github.com-fs:flying-sausages/swizzin
flying-sausages May 10, 2020
88bc695
Merge branch 'master' of github.com-fs:flying-sausages/swizzin
flying-sausages May 15, 2020
e345f76
Merge branch 'master' of github.com-fs:flying-sausages/swizzin
flying-sausages May 22, 2020
6a3326d
Mango installer and remover
flying-sausages May 23, 2020
f35614e
Mango upgrader
flying-sausages May 23, 2020
d2c90a8
Bit of formatting, removing testing supports
flying-sausages May 23, 2020
677a825
A stab hat doesn't work right now as here is no Baseurl support curre…
flying-sausages May 23, 2020
3c16fd9
Remove comments
flying-sausages May 23, 2020
b184b7b
Shut up linter
flying-sausages May 23, 2020
9c39387
wget sraight to destination, allow access to the library
flying-sausages May 23, 2020
1f36426
Fix wget call, add catch for failure
flying-sausages May 23, 2020
0422b4c
Abstract mango system user name, change variable name for the created…
flying-sausages May 23, 2020
cbd1035
more linter hushhhh
flying-sausages May 23, 2020
6253a47
i give up
flying-sausages May 23, 2020
0b9e7fc
Added configuration for BaseUrl
flying-sausages May 24, 2020
a683685
Add nginx config removal
flying-sausages May 24, 2020
b948d94
FIx Nginx config for good!
flying-sausages May 24, 2020
b75acd7
Print out the location of the library
flying-sausages May 24, 2020
ac2ddfd
Add warning about unsupported domains
flying-sausages May 26, 2020
5734eb6
Merge branch 'master' of github.com-fs:flying-sausages/swizzin
flying-sausages May 28, 2020
4bf41dd
Merge branch 'master' of github.com-fs:flying-sausages/swizzin
flying-sausages Jun 2, 2020
aafc725
Mango installer and remover
flying-sausages May 23, 2020
7ba7e5f
Mango upgrader
flying-sausages May 23, 2020
b81d440
Bit of formatting, removing testing supports
flying-sausages May 23, 2020
40de8c1
A stab hat doesn't work right now as here is no Baseurl support curre…
flying-sausages May 23, 2020
41ae45b
Remove comments
flying-sausages May 23, 2020
46148b5
Shut up linter
flying-sausages May 23, 2020
55af48a
wget sraight to destination, allow access to the library
flying-sausages May 23, 2020
7014bd6
Fix wget call, add catch for failure
flying-sausages May 23, 2020
8861052
Abstract mango system user name, change variable name for the created…
flying-sausages May 23, 2020
5415e83
more linter hushhhh
flying-sausages May 23, 2020
155cec5
i give up
flying-sausages May 23, 2020
bf85c18
Added configuration for BaseUrl
flying-sausages May 24, 2020
9c7760e
Add nginx config removal
flying-sausages May 24, 2020
5139bc6
FIx Nginx config for good!
flying-sausages May 24, 2020
eae209b
Print out the location of the library
flying-sausages May 24, 2020
d78c64d
Merge branch 'mango' of github.com-fs:flying-sausages/swizzin into mango
flying-sausages Jun 2, 2020
9ecb952
Added user creation to mango install
flying-sausages Jun 3, 2020
8d4ae4e
+
flying-sausages Jun 3, 2020
7844f06
Move .config path, simplify functions
flying-sausages Jun 3, 2020
2b6f400
Showing generated password.
flying-sausages Jun 3, 2020
10351ae
Add user management capabilities to mango through box
flying-sausages Jun 3, 2020
e96642c
Added change password commands
flying-sausages Jun 3, 2020
5d39c5a
oops
flying-sausages Jun 3, 2020
3a76a65
Rename binary
flying-sausages Jun 3, 2020
22f5f18
Merge branch 'master' into mango
flying-sausages Aug 8, 2020
1f44627
Various small refinements
flying-sausages Aug 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions scripts/box
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function _adduser {
echo "D /var/run/${user} 0750 ${user} ${user} -" >> /etc/tmpfiles.d/${user}.conf
systemd-tmpfiles /etc/tmpfiles.d/${user}.conf --create

for app in rtorrent rutorrent deluge autodl flood nzbget lounge transmission wireguard organizr; do
for app in rtorrent rutorrent deluge autodl flood nzbget lounge transmission wireguard organizr mango; do
if [[ $app = "rutorrent" ]]; then
if [[ -d /srv/rutorrent ]]; then
if [[ ! -f /install/.rutorrent.lock ]]; then touch /install/.rutorrent.lock; fi
Expand All @@ -268,8 +268,8 @@ function _adduser {
app="{deluged,deluge-web}"
eval systemctl enable ${app}@${user}
eval systemctl start ${app}@${user}
elif [[ $app =~ ("rutorrent"|"lounge"|"organizr") ]]; then
:
elif [[ $app =~ ("rutorrent"|"lounge"|"organizr"|"mango") ]]; then
: #Multi-user app without user service files
else
if [[ $app = "autodl" ]]; then app=irssi; fi
systemctl enable ${app}@${user}
Expand Down Expand Up @@ -309,7 +309,8 @@ function _deluser {
echo
read -rep 'Removal will start as soon as you confirm this message. Press enter to continue.'

for app in rtorrent rutorrent deluge autodl flood nzbget lounge transmission wireguard organizr; do

for app in rtorrent rutorrent deluge autodl flood nzbget lounge transmission mango wireguard organizr; do
if [[ $app = "rutorrent" ]]; then
if [[ -d /srv/rutorrent ]]; then
if [[ ! -f /install/.rutorrent.lock ]]; then touch /install/.rutorrent.lock; fi
Expand All @@ -323,6 +324,9 @@ function _deluser {
rm -f /etc/nginx/apps/${user}*
elif [[ $app = "lounge" ]]; then
su -s /bin/sh lounge -c "thelounge remove ${user}" > /dev/null
elif [[ $app = "mango" ]]; then
if [[ -z $mangodir ]]; then mangodir="/opt/mango"; fi
su mango -c "$mangodir/mango admin user delete ${user}"
elif [[ $app = "wireguard" ]]; then
rm -f /home/${user}/.wireguard/client
systemctl disable --now wg-quick@wg$(id -u "$user")
Expand Down Expand Up @@ -411,6 +415,10 @@ function _chpasswd {
if [[ -f /install/.lounge.lock ]]; then
su -s /bin/sh lounge -c "thelounge reset $user " <<< "${pass}" > /dev/null
fi
if [[ -f /install/.mango.lock ]]; then
if [[ -z $mangodir ]]; then mangodir="/opt/mango"; fi
su mango -c "$mangodir/mango admin user update ${user} -p ${pass}"
fi
if [[ -f /install/.organizr.lock ]]; then
#TODO fix when API allows to
echo "Remember to manually change the organizr account's password!"
Expand Down
136 changes: 136 additions & 0 deletions scripts/install/mango.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#! /bin/bash
# Mango installer by flying_sausages for Swizzin 2020

# shellcheck source=sources/functions/utils
. /etc/swizzin/sources/functions/utils

if [[ -f /tmp/.install.lock ]]; then
log="/root/logs/install.log"
else
log="/root/logs/swizzin.log"
fi

mangodir="/opt/mango"
mangousr="mango"


# Downloading the latest binary
function _install_mango () {
echo "Downloading binary" | tee -a $log
dlurl=$(curl -s https://api.github.com/repos/hkalexling/Mango/releases/latest | grep "browser_download_url" | head -1 | cut -d\" -f 4)
# shellcheck disable=SC2181
if [[ $? != 0 ]]; then
echo "Failed to query github" | tee -a $log
exit 1
fi

mkdir -p "$mangodir"
mkdir -p "$mangodir"/library
wget "${dlurl}" -O $mangodir/mango >> $log 2>&1
# shellcheck disable=SC2181
if [[ $? != 0 ]]; then
echo "Failed to download binary" | tee -a $log
exit 1
fi

chmod +x $mangodir/mango
chmod o+rx -R $mangodir $mangodir/library

useradd $mangousr --system -d "$mangodir" >> $log 2>&1
sudo chown -R $mangousr:$mangousr $mangodir

}

## Creating config
function _mkconf_mango () {
mkdir -p $mangodir/.config/mango
cat > "$mangodir/.config/mango/config.yml" <<CONF
#Please do not edit as swizzin will be replacing this file as updates roll out.
port: 9003
base_url: /
library_path: $mangodir/library
db_path: $mangodir/.config/mango/mango.db
scan_interval_minutes: 5
log_level: info
upload_path: $mangodir/uploads
disable_ellipsis_truncation: false
mangadex:
base_url: https://mangadex.org
api_url: https://mangadex.org/api
download_wait_seconds: 5
download_retries: 4
download_queue_db_path: $mangodir/.config/mango/queue.db
chapter_rename_rule: '[Vol.{volume} ][Ch.{chapter} ]{title|id}'
manga_rename_rule: '{title}'
CONF
chown $mangousr:$mangousr -R $mangodir
chmod o-rwx $mangodir/.config
}

# Creating systemd unit
function _mkservice_mango(){
cat > /etc/systemd/system/mango.service <<SYSD
# Service file example for Mango
[Unit]
Description=Mango - Manga Server and Web Reader
After=network.target

[Service]
User=$mangousr
ExecStart=$mangodir/mango
Restart=on-abort
TimeoutSec=20

[Install]
WantedBy=multi-user.target
SYSD
systemctl daemon-reload >> $log 2>&1
systemctl enable --now mango >> $log 2>&1
}

# Creating all users' accounts
_addusers_mango () {
echo "Adding user(s)"
for u in "${users[@]}"; do
pass=$(_get_user_password "$u")
if [[ $u = "$master" ]]; then
su $mangousr -c "$mangodir/mango admin user add -u $master -p $pass --admin"
else
# pass=$(cut -d: -f2 < /root/"$u".info)
passlen=${#pass}
if [[ $passlen -ge 6 ]]; then
su $mangousr -c "$mangodir/mango admin user add -u $u -p $pass"
else
pass=$(openssl rand -base64 32)
echo "WARNING: $u's password too short for mango, please change the password using 'box chpasswd $u'" | tee -a $log
echo "Mango account temporarily set up with the password '$pass'"
su $mangousr -c "$mangodir/mango admin user add -u $u -p $pass"
fi
fi
done
}

########## MAIN

master=$(cut -d: -f1 < /root/.master.info)
users=($(cut -d: -f1 < /etc/htpasswd))

if [[ -n $1 ]]; then
users=("$1")
_addusers_mango
exit 0
fi

_install_mango
_mkconf_mango
_addusers_mango
_mkservice_mango

if [[ -f /install/.nginx.lock ]]; then
bash /etc/swizzin/scripts/nginx/mango.sh
fi

echo "Please use your existing credentials when logging in."
echo "You can access your files in $mangodir/library" | tee -a /root/mango.info

touch /install/.mango.lock
13 changes: 13 additions & 0 deletions scripts/nginx/mango.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
# Nginx configuration for Mango

cat > /etc/nginx/apps/mango.conf <<EOF
location /mango/ {
proxy_pass http://localhost:9003/;
}
EOF

sed -i 's=base_url: /=base_url: /mango=' /opt/mango/.config/mango/config.yml
systemctl restart mango

systemctl reload nginx
22 changes: 22 additions & 0 deletions scripts/remove/mango.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /bin/bash
# Mango deyeeter by flying_sausages 2020 for swizzin

if [[ -f /tmp/.install.lock ]]; then
log="/root/logs/install.log"
else
log="/root/logs/swizzin.log"
fi

rm -rf /opt/mango
systemctl disable --now mango >> $log 2>&1
rm /etc/systemd/system/mango.service
systemctl daemon-reload >> $log 2>&1

if [[ -f /install/.nginx.lock ]]; then
rm /etc/nginx/apps/mango.conf
systemctl reload nginx
fi

userdel mango -f -r >> $log 2>&1

rm /install/.mango.lock
45 changes: 45 additions & 0 deletions scripts/upgrade/mango.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#! /bin/bash
# Mango upgrader
# flying_sausages for swizzin 2020

if [[ -f /tmp/.install.lock ]]; then
log="/root/logs/install.log"
else
log="/root/logs/swizzin.log"
fi

if [[ ! -f /install/.mango.lock ]]; then
echo "Mango not installed"
exit 1
fi

if [[ $(systemctl is-active mango) == "active" ]]; then
wasActive="true"
systemctl stop mango
fi

rm -rf /tmp/mangobak

mkdir /tmp/mangobak
cp -t /tmp/mangobak /opt/mango/mango /opt/mango/config.yml

echo "Downloading binary" | tee -a $log
dlurl=$(curl -s https://api.github.com/repos/hkalexling/Mango/releases/latest | grep "browser_download_url" | head -1 | cut -d\" -f 4)
# shellcheck disable=SC2181
if [[ $? != 0 ]]; then
echo "Failed to query github"
exit 1
fi
wget "${dlurl}" -O $mangodir/mango >> $log 2>&1


mangodir="/opt/mango"

# mkdir -p "$mangodir"
# cp /tmp/mango $mangodir/mango
chmod +x "$mangodir"/mango


if [[ $wasActive = "true" ]]; then
systemctl start mango
fi