mirror of
https://github.com/endeavouros-team/eos-bash-shared.git
synced 2026-06-13 01:34:36 +00:00
99 lines
3.3 KiB
Bash
Executable File
99 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Copy additional wallpapers from Github or Gitlab EOS site.
|
|
|
|
Main() {
|
|
local -r gitlab="https://gitlab.com/endeavouros-filemirror/Community-wallpapers/-/archive/main/Community-wallpapers-main.zip"
|
|
local -r github="https://github.com/EndeavourOS-Community-Editions/Community-wallpapers/archive/refs/heads/main.zip"
|
|
local url="$gitlab"
|
|
|
|
source /etc/eos-script-lib-yad.conf || return 1
|
|
case "$EOS_FILESERVER_SITE" in
|
|
github) url="$github" ;;
|
|
gitlab) ;;
|
|
*) DIE "value '$EOS_FILESERVER_SITE' of variable EOS_FILESERVER_SITE is not supported." ;;
|
|
esac
|
|
|
|
local progname=${0##*/}
|
|
local workdir=""
|
|
local dirtodel=""
|
|
local backup=no
|
|
local -r walldir=/usr/share/endeavouros/backgrounds
|
|
local -r zipdir=Community-wallpapers-main
|
|
local dloader=wget
|
|
|
|
Options "$@"
|
|
|
|
if [ "$workdir" ] ; then
|
|
# user managed $workdir
|
|
[ -d "$workdir" ] || DIE "working directory '$workdir' does not exist."
|
|
[ -w "$workdir" ] || DIE "working directory '$workdir' cannot be written."
|
|
else
|
|
# temporary $workdir
|
|
workdir=$(mktemp -d) || DIE "cannot create a working directory under '/tmp'."
|
|
chmod go-rwx "$workdir"
|
|
dirtodel="$workdir"
|
|
fi
|
|
echo "Downloading wallpapers, please wait ..." >&2
|
|
case "$dloader" in
|
|
wget) wget -O "$workdir"/Community-wallpapers.zip "$url" || DIE "wget failed, code $?" ;;
|
|
curl) curl -Lm 300 -o "$workdir"/Community-wallpapers.zip "$url" || DIE "curl failed, code $?" ;;
|
|
esac
|
|
|
|
echo "Moving wallpapers under $walldir ..." >&2
|
|
unzip -qd "$workdir" "$workdir"/Community-wallpapers.zip || exit 1
|
|
rm -f "$workdir"/Community-wallpapers.zip
|
|
rm -f "$workdir/$zipdir"/{community-wallpapers.png,README.md}
|
|
rm -rf "$workdir/$zipdir"/scripts
|
|
|
|
if [ $backup = yes ] ; then
|
|
sudo rm -rf $walldir/eos_wallpapers_{classic,community}.bak
|
|
sudo mv $walldir/eos_wallpapers_classic $walldir/eos_wallpapers_classic.bak
|
|
sudo mv $walldir/eos_wallpapers_community $walldir/eos_wallpapers_community.bak
|
|
else
|
|
sudo rm -rf $walldir/{eos_wallpapers_classic,eos_wallpapers_community}
|
|
fi
|
|
|
|
sudo cp -r "$workdir/$zipdir"/eos_wallpapers_* $walldir/ || exit 1
|
|
if [ "$dirtodel" = "$workdir" ] ; then
|
|
rm -rf "$workdir"
|
|
else
|
|
rm -rf "$workdir/$zipdir"
|
|
fi
|
|
|
|
}
|
|
|
|
Options() {
|
|
local arg
|
|
for arg in "$@" ; do
|
|
case "$arg" in
|
|
--github) url="${URLs[github]}" ;;
|
|
--gitlab) url="${URLs[gitlab]}" ;;
|
|
--wget) dloader=wget ;;
|
|
--curl) dloader=curl ;;
|
|
--backup) backup=yes ;;
|
|
--workdir=*) workdir="${arg#*=}" ;;
|
|
-h | --help) Help 0 ;;
|
|
*) DIE "parameter '$arg' is not supported." ;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
Help() {
|
|
cat <<EOF
|
|
Usage: $progname [options]
|
|
Options: -h, --help This help.
|
|
--gitlab Download wallpapers from EndeavourOS pages at gitlab (default).
|
|
--github Download wallpapers from EndeavourOS pages at github.
|
|
--wget Use wget to download wallpapers (default).
|
|
--curl Use curl to download wallpapers.
|
|
--backup Backup existing wallpapers to $walldir/*.bak.
|
|
Default: no backups made.
|
|
EOF
|
|
[ "$1" ] && exit $1
|
|
}
|
|
|
|
DIE() { echo "$progname: error: $1" >&2; Help 1; }
|
|
|
|
Main "$@"
|