change to curl and check for font name
This commit is contained in:
parent
6be2cdfd15
commit
c73fd6c1ce
1 changed files with 73 additions and 14 deletions
|
@ -11,14 +11,6 @@ cur_dir=$(dirname "${0}")
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
[ -r "${cur_dir}/shared_functions.sh" ] && . "${cur_dir}/shared_functions.sh"
|
[ -r "${cur_dir}/shared_functions.sh" ] && . "${cur_dir}/shared_functions.sh"
|
||||||
|
|
||||||
wallpaper_file="${HOME}/wallpaper.jpg"
|
|
||||||
wallpaper_file2="/etc/lightdm/background.jpg"
|
|
||||||
archive_folder="${HOME}/earth_pics"
|
|
||||||
screen_width=1366
|
|
||||||
# `convert -list font` to get the list of fonts
|
|
||||||
font_name="Bitstream-Vera-Sans"
|
|
||||||
gsettings_cmd=$(which gsettings)
|
|
||||||
font_name=$("${gsettings_cmd}" get org.gnome.desktop.interface font-name | sed "s/'//g" | sed 's/ [0-9]*$//g')
|
|
||||||
check_internet() {
|
check_internet() {
|
||||||
default_route=$(/sbin/route -n | egrep "^0.0.0.0")
|
default_route=$(/sbin/route -n | egrep "^0.0.0.0")
|
||||||
if [ "$default_route" == "" ]; then
|
if [ "$default_route" == "" ]; then
|
||||||
|
@ -27,13 +19,80 @@ check_internet() {
|
||||||
ping -q -c 2 en.wikipedia.org &> /dev/null
|
ping -q -c 2 en.wikipedia.org &> /dev/null
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_font() {
|
||||||
|
font_name="${1}"
|
||||||
|
convert_cmd="$(which conver)"
|
||||||
|
if "${convert_cmd}" -list font | grep Font: | awk '{print($2)}' | grep font_name > /dev/null; then
|
||||||
|
return "${font_name}"
|
||||||
|
else
|
||||||
|
new_font_name="$("${convert_cmd}" -list font | grep Font: | awk '{print($2)}' |head -n 1)"
|
||||||
|
if [ "${new_font_name}" != "" ]; then
|
||||||
|
message "Couldn't find font '${font_name}' in the list from convert, so I'm using the first '${new_font_name}'"
|
||||||
|
return "${new_font_name}"
|
||||||
|
else
|
||||||
|
message "Error. No fonts available for convert!" p
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
wallpaper_file="${HOME}/wallpaper.jpg"
|
||||||
|
wallpaper_file2="/etc/lightdm/background.jpg"
|
||||||
|
archive_folder="${HOME}/earth_pics"
|
||||||
|
screen_width=1366
|
||||||
|
# `convert -list font` to get the list of fonts
|
||||||
|
font_name="Bitstream-Vera-Sans"
|
||||||
|
gsettings_cmd=$(which gsettings)
|
||||||
|
font_name=$("${gsettings_cmd}" get org.gnome.desktop.interface font-name | sed "s/'//g" | sed 's/ [0-9]*$//g')
|
||||||
|
|
||||||
|
while [ $# -gt 0 ]
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
"--wallpaper-file")
|
||||||
|
shift
|
||||||
|
wallpaper_file="${1}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
"--archive-folder")
|
||||||
|
shift
|
||||||
|
archive_folder="${1}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
"--screen-width")
|
||||||
|
shift
|
||||||
|
screen_width="${1}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
"--font-name")
|
||||||
|
shift
|
||||||
|
font_name="${1}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
"--debug")
|
||||||
|
shift
|
||||||
|
DEBUG=1
|
||||||
|
;;
|
||||||
|
'--logfile')
|
||||||
|
shift
|
||||||
|
LOG_FILE="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
message "Unknown parameter '${1}'"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
check_internet || exit 1
|
check_internet || exit 1
|
||||||
|
|
||||||
|
font_name="$(check_font "${font_name}")"
|
||||||
message "Using font '${font_name}'"
|
message "Using font '${font_name}'"
|
||||||
|
|
||||||
wget_cmd=$(which wget)
|
curl_cmd=$(which curl)
|
||||||
if [ -z ${wget_cmd} ]; then
|
if [ -z ${curl_cmd} ]; then
|
||||||
echo "It seems like wget is not installed."
|
echo "It seems like curl is not installed."
|
||||||
exit 3
|
exit 3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -46,7 +105,7 @@ str_city=$(echo "$city" | sed "s/ /_/g" -)
|
||||||
message "str_city $str_city"
|
message "str_city $str_city"
|
||||||
wiki_url="https://en.wikipedia.org/wiki/$str_city"
|
wiki_url="https://en.wikipedia.org/wiki/$str_city"
|
||||||
message "wiki_url $wiki_url"
|
message "wiki_url $wiki_url"
|
||||||
wiki_content=$("${wget_cmd}" -q -O - $wiki_url)
|
wiki_content=$("${curl_cmd}" -s $wiki_url)
|
||||||
latitude=$(echo $wiki_content | egrep -o "[0-9]{1,2}°[0-9]?[0-9]?′?[0-9]?[0-9]?″?[NS]" | head -n 1)
|
latitude=$(echo $wiki_content | egrep -o "[0-9]{1,2}°[0-9]?[0-9]?′?[0-9]?[0-9]?″?[NS]" | head -n 1)
|
||||||
message "latitude $latitude"
|
message "latitude $latitude"
|
||||||
longitude=$(echo $wiki_content | egrep -o "[0-9]{1,2}°[0-9]?[0-9]?′?[0-9]?[0-9]?″?[EW]" | head -n 1)
|
longitude=$(echo $wiki_content | egrep -o "[0-9]{1,2}°[0-9]?[0-9]?′?[0-9]?[0-9]?″?[EW]" | head -n 1)
|
||||||
|
@ -103,7 +162,7 @@ date="$cur_date_$time"
|
||||||
if [[ -e $wallpaper_file ]]; then
|
if [[ -e $wallpaper_file ]]; then
|
||||||
rm "${wallpaper_file}" -rf
|
rm "${wallpaper_file}" -rf
|
||||||
fi
|
fi
|
||||||
"${wget_cmd}" -q $url -O $wallpaper_file
|
"${curl_cmd}" -s $url > $wallpaper_file
|
||||||
error_code=$?
|
error_code=$?
|
||||||
if [[ "$error_code" != "0" ]]; then
|
if [[ "$error_code" != "0" ]]; then
|
||||||
echo "Error $error_code downloading image from '$url' to '$wallpaper_file'"
|
echo "Error $error_code downloading image from '$url' to '$wallpaper_file'"
|
||||||
|
@ -116,7 +175,7 @@ if [[ "$o_longitude" == "West" ]]; then
|
||||||
g_longitude="-$g_longitude"
|
g_longitude="-$g_longitude"
|
||||||
fi
|
fi
|
||||||
weather_url="http://api.wunderground.com/api/be78b9c2c0dbd00f/conditions/lang:ES/q/$g_latitude,$g_longitude.xml"
|
weather_url="http://api.wunderground.com/api/be78b9c2c0dbd00f/conditions/lang:ES/q/$g_latitude,$g_longitude.xml"
|
||||||
temperature=$("${wget_cmd}" -q -O - "$weather_url" | egrep -o "<temp_c>-?[0-9]*\.?[0-9]?</temp_c>" | sed "s/<temp_c>//g" - | sed "s|</temp_c>||g" -)
|
temperature=$("${curl_cmd}" -s "$weather_url" | egrep -o "<temp_c>-?[0-9]*\.?[0-9]?</temp_c>" | sed "s/<temp_c>//g" - | sed "s|</temp_c>||g" -)
|
||||||
text="Image from $cur_date at $time\n$city $temperatureº C"
|
text="Image from $cur_date at $time\n$city $temperatureº C"
|
||||||
convert_cmd=$(which convert)
|
convert_cmd=$(which convert)
|
||||||
if [ ! -x "${convert_cmd}" ]; then
|
if [ ! -x "${convert_cmd}" ]; then
|
||||||
|
|
Loading…
Reference in a new issue