archwiki_downloader/awdl
2020-04-10 02:36:53 +02:00

68 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
# archwiki downloader
# as there's no fedora pkg atm, let's do this ourselves
# inspiration taken from PKGBUILDs of arch-wiki-docs and arch-wiki-lite
# https://git.archlinux.org/svntogit/community.git/tree/trunk?h=packages/arch-wiki-docs
# https://git.archlinux.org/svntogit/community.git/tree/trunk?h=packages/arch-wiki-lite
#
# deps: python3 python3-simplemediawiki python3-cssselect python3-lxml dialog
# plus I used rsync, feel free to change it to cp (and some paths accordingly)
#
# author of this little script
# -- wanderer
# https://dotya.ml/contact/
# license: wtfpl
echo -e "archwiki downloader"
if [ $(id -u) != 0 ]; then
echo "[x] not root, not running, sorry"
exit 9001
fi
deps=("python3" "python3-simplemediawiki" "python3-cssselect" "python3-lxml" "dialog" "rsync")
echo "[*] checking deps"
for pkg in "${deps[@]}"; do
dnf list installed $pkg > /dev/null 2>&1
if [ $(echo $?) -eq 1 ]; then
echo "[x] package \"$pkg\" could not be found"
echo "[i] you can install the dependencies with the following command"
echo "dnf install ${deps[*]}"
echo "[*] exiting now" && exit 9001
fi
done
dest_html=/usr/share/doc/arch-wiki/html/
dest_text=/usr/share/doc/arch-wiki/text/
mkdir -pv $dest_html
mkdir -pv $dest_text
mktemp -d && cd /tmp/$(ls -t /tmp | grep tmp. | head -1)
workdir=$(pwd)
mkdir -pv $workdir/build_wiki
mkdir -pv /etc/dialog.d/
echo "[*] getting sources"
curl http://kmkeen.com/arch-wiki-lite/arch-wiki-lite.tar.gz | bsdtar xfv -
git clone https://github.com/lahwaacz/arch-wiki-docs.git
echo "[*] getting archwiki files"
cd $workdir/arch-wiki-docs
LANG=en_US.UTF-8 python3 arch-wiki-docs.py --output-directory $workdir/build_wiki --clean --safe-filenames
rsync -auvP build_wiki/ $dest_html
echo "[*] generating text file"
cd $workdir/arch-wiki-lite
LC_ALL=en_US.UTF-8 python3 wiki_lite.py
rsync -auvP wiki/ $dest_text
rsync -auvP wiki-search wiki-search-html /bin/
chmod -v 0755 /bin/wiki-search
chmod -v 0755 /bin/wiki-search-html
rsync -auvP wiki-search.dialog.rc /etc/dialog.d/
echo "[*] done, removing workdir"
cd $workdir/../
trap "rm -rfv $workdir" 0 1 3 15 9001
exit $?