#!/usr/bin/env bash

# Delete file only if file exists
# remove <file1> <file2> ...
function remove () {
    local _list
    local _file
    _list=($(echo "$@"))
    for _file in "${_list[@]}"; do
        if [[ -f ${_file} ]]; then
            rm -f "${_file}"
        elif [[ -d ${_file} ]]; then
            rm -rf "${_file}"
        fi
    done
}

image="${1}"
replace="${2}"

# Replace wallpaper.
remove "/usr/share/backgrounds/xfce/xfce-${image}.png"
ln -s "/usr/share/backgrounds/${replace}.jpg" "/usr/share/backgrounds/xfce/xfce-${image}.png"
chmod 644 "/usr/share/backgrounds/${replace}.jpg"