Reverted date commands to GNU Date commands
Added detection of date version. Tries to use gdate
This commit is contained in:
parent
4f2e022471
commit
cae7d16376
1 changed files with 30 additions and 22 deletions
52
bb.sh
52
bb.sh
|
@ -152,8 +152,6 @@ global_variables() {
|
||||||
# The locale to use for the dates displayed on screen (not for the timestamps)
|
# The locale to use for the dates displayed on screen (not for the timestamps)
|
||||||
date_format="%B %d, %Y"
|
date_format="%B %d, %Y"
|
||||||
date_locale="C"
|
date_locale="C"
|
||||||
# Date options which work on both BSD and GNU date variants
|
|
||||||
date_R='+%a, %d %h %Y %H:%M:%S %z'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Prints the required google analytics code
|
# Prints the required google analytics code
|
||||||
|
@ -184,8 +182,7 @@ google_analytics() {
|
||||||
#
|
#
|
||||||
# $1 the file to edit
|
# $1 the file to edit
|
||||||
edit() {
|
edit() {
|
||||||
# timestamp="$(date -r $1 +'%Y%m%d%k%M')"
|
timestamp="$(date -r $1 +'%Y%m%d%k%M')"
|
||||||
timestamp="$(stat -f "%Sm" -t '%Y%m%d%k%M' $1)"
|
|
||||||
$EDITOR "$1"
|
$EDITOR "$1"
|
||||||
touch -t $timestamp "$1"
|
touch -t $timestamp "$1"
|
||||||
}
|
}
|
||||||
|
@ -246,11 +243,9 @@ create_html_page() {
|
||||||
echo "$title" >> "$filename"
|
echo "$title" >> "$filename"
|
||||||
echo '</a></h3>' >> "$filename"
|
echo '</a></h3>' >> "$filename"
|
||||||
if [ "$timestamp" == "" ]; then
|
if [ "$timestamp" == "" ]; then
|
||||||
# echo '<div class="subtitle">'$(LC_ALL=date_locale date +"$date_format")' — ' >> "$filename"
|
echo '<div class="subtitle">'$(LC_ALL=date_locale date +"$date_format")' — ' >> "$filename"
|
||||||
echo '<div class="subtitle">'$(date "$date_R")' — ' >> "$filename"
|
|
||||||
else
|
else
|
||||||
# echo '<div class="subtitle">'$(LC_ALL=date_locale date +"$date_format" --date="$timestamp") ' — ' >> "$filename"
|
echo '<div class="subtitle">'$(LC_ALL=date_locale date +"$date_format" --date="$timestamp") ' — ' >> "$filename"
|
||||||
echo '<div class="subtitle">'"$timestamp"' — ' >> "$filename"
|
|
||||||
fi
|
fi
|
||||||
echo "$global_author</div>" >> "$filename"
|
echo "$global_author</div>" >> "$filename"
|
||||||
echo '<!-- text begin -->' >> "$filename" # This marks the text body, after the title, date...
|
echo '<!-- text begin -->' >> "$filename" # This marks the text body, after the title, date...
|
||||||
|
@ -381,8 +376,7 @@ all_posts() {
|
||||||
title="$(awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' $i)"
|
title="$(awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' $i)"
|
||||||
echo -n '<li><a href="'$global_url/$i'">'$title'</a> —' >> "$contentfile"
|
echo -n '<li><a href="'$global_url/$i'">'$title'</a> —' >> "$contentfile"
|
||||||
# Date
|
# Date
|
||||||
#date="$(LC_ALL=date_locale date -r "$i" +"$date_format")"
|
date="$(LC_ALL=date_locale date -r "$i" +"$date_format")"
|
||||||
date="$(stat -f "%Sm" -t "%a, %d %h %Y %H:%M:%S %z")"
|
|
||||||
echo " $date</li>" >> "$contentfile"
|
echo " $date</li>" >> "$contentfile"
|
||||||
done
|
done
|
||||||
echo ""
|
echo ""
|
||||||
|
@ -441,7 +435,7 @@ list_posts() {
|
||||||
n=1
|
n=1
|
||||||
for i in $(ls -t *.html); do
|
for i in $(ls -t *.html); do
|
||||||
if [ "$i" == "$index_file" ] || [ "$i" == "$archive_index" ]; then continue; fi
|
if [ "$i" == "$index_file" ] || [ "$i" == "$archive_index" ]; then continue; fi
|
||||||
line="$n # $(awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' $i) # $(stat -f "%Sm" -t "%a, %d %h %Y %H:%M:%S %z" $i)"
|
line="$n # $(awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' $i) # $(LC_ALL=date_locale date -r $i +"date_format")"
|
||||||
lines="${lines}""$line""\n" # Weird stuff needed for the newlines
|
lines="${lines}""$line""\n" # Weird stuff needed for the newlines
|
||||||
n=$(( $n + 1 ))
|
n=$(( $n + 1 ))
|
||||||
done
|
done
|
||||||
|
@ -460,8 +454,8 @@ make_rss() {
|
||||||
echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">' >> "$rssfile"
|
echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">' >> "$rssfile"
|
||||||
echo '<channel><title>'$global_title'</title><link>'$global_url'</link>' >> "$rssfile"
|
echo '<channel><title>'$global_title'</title><link>'$global_url'</link>' >> "$rssfile"
|
||||||
echo '<description>'$global_description'</description><language>en</language>' >> "$rssfile"
|
echo '<description>'$global_description'</description><language>en</language>' >> "$rssfile"
|
||||||
echo '<lastBuildDate>'$(date "$date_R")'</lastBuildDate>' >> "$rssfile"
|
echo '<lastBuildDate>'$(date -R)'</lastBuildDate>' >> "$rssfile"
|
||||||
echo '<pubDate>'$(date "$date_R")'</pubDate>' >> "$rssfile"
|
echo '<pubDate>'$(date -R)'</pubDate>' >> "$rssfile"
|
||||||
echo '<atom:link href="'$global_url/$blog_feed'" rel="self" type="application/rss+xml" />' >> "$rssfile"
|
echo '<atom:link href="'$global_url/$blog_feed'" rel="self" type="application/rss+xml" />' >> "$rssfile"
|
||||||
|
|
||||||
n=0
|
n=0
|
||||||
|
@ -477,9 +471,8 @@ make_rss() {
|
||||||
echo "]]></description><link>$global_url/$i</link>" >> "$rssfile"
|
echo "]]></description><link>$global_url/$i</link>" >> "$rssfile"
|
||||||
echo "<guid>$global_url/$i</guid>" >> "$rssfile"
|
echo "<guid>$global_url/$i</guid>" >> "$rssfile"
|
||||||
echo "<dc:creator>$global_author</dc:creator>" >> "$rssfile"
|
echo "<dc:creator>$global_author</dc:creator>" >> "$rssfile"
|
||||||
|
echo '<pubDate>'$(date -r "$i" -R)'</pubDate></item>' >> "$rssfile"
|
||||||
|
|
||||||
#echo '<pubDate>'$(date -r "$i" -R)'</pubDate></item>' >> "$rssfile"
|
|
||||||
echo '<pubDate>'$(stat -f "%Sm" -t "%a, %d %h %Y %H:%M:%S %z" "$i" )'</pubDate></item>' >> "$rssfile"
|
|
||||||
n=$(( $n + 1 ))
|
n=$(( $n + 1 ))
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -575,13 +568,11 @@ rebuild_all_entries() {
|
||||||
awk '/<!-- text begin -->/, /<!-- text end -->/{if (!/<!-- text begin -->/ && !/<!-- text end -->/) print}' "$i" >> "$contentfile"
|
awk '/<!-- text begin -->/, /<!-- text end -->/{if (!/<!-- text begin -->/ && !/<!-- text end -->/) print}' "$i" >> "$contentfile"
|
||||||
|
|
||||||
# Original post timestamp
|
# Original post timestamp
|
||||||
|
timestamp="$(date -R -r $i)"
|
||||||
|
|
||||||
#timestamp="$(date -R -r $i)"
|
|
||||||
timestamp="$(stat -f "%Sm" -t "%a, %d %h %Y %H:%M:%S %z" $i)"
|
|
||||||
create_html_page "$contentfile" "$i.rebuilt" no "$title" "$timestamp"
|
create_html_page "$contentfile" "$i.rebuilt" no "$title" "$timestamp"
|
||||||
# keep the original timestamp!
|
# keep the original timestamp!
|
||||||
#timestamp="$(date -r $i +'%Y%m%d%k%M')"
|
timestamp="$(date -r $i +'%Y%m%d%k%M')"
|
||||||
timestamp="$(stat -f "%Sm" -t '%Y%m%d%k%M' $i)"
|
|
||||||
mv "$i.rebuilt" "$i"
|
mv "$i.rebuilt" "$i"
|
||||||
chmod 644 "$i"
|
chmod 644 "$i"
|
||||||
touch -t $timestamp "$i"
|
touch -t $timestamp "$i"
|
||||||
|
@ -621,14 +612,31 @@ reset() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
date_version_detect() {
|
||||||
|
if !(date --version >/dev/null 2>&1) ; then
|
||||||
|
# date utility is BSD. Test if gdate is installed
|
||||||
|
if gdate --version >/dev/null 2>&1 ; then
|
||||||
|
alias date=gdate
|
||||||
|
echo Using gdate.
|
||||||
|
else
|
||||||
|
echo ERROR: Not GNU date found.
|
||||||
|
echo Try installing gdate utility or coreutils.
|
||||||
|
echo Exiting...
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Main function
|
# Main function
|
||||||
# Encapsulated on its own function for readability purposes
|
# Encapsulated on its own function for readability purposes
|
||||||
#
|
#
|
||||||
# $1 command to run
|
# $1 command to run
|
||||||
# $2 file name of a draft to continue editing (optional)
|
# $2 file name of a draft to continue editing (optional)
|
||||||
do_main() {
|
do_main() {
|
||||||
|
# Detect if using BSD date or GNU date
|
||||||
|
date_version_detect
|
||||||
# Use config file or fallback to inline configuration
|
# Use config file or fallback to inline configuration
|
||||||
source "$global_config" || global_variables
|
source "$global_config" &> /dev/null || global_variables
|
||||||
|
|
||||||
# Check for $EDITOR
|
# Check for $EDITOR
|
||||||
if [[ -z "$EDITOR" ]]; then
|
if [[ -z "$EDITOR" ]]; then
|
||||||
|
@ -663,8 +671,8 @@ do_main() {
|
||||||
# We're going to back up just in case
|
# We're going to back up just in case
|
||||||
ls *.html &> /dev/null
|
ls *.html &> /dev/null
|
||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
tar cfz ".backup.tar.gz" *.html
|
tar cfz ".backup.tar.gz" *.html
|
||||||
chmod 600 ".backup.tar.gz"
|
chmod 600 ".backup.tar.gz"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" == "reset" ]; then
|
if [ "$1" == "reset" ]; then
|
||||||
|
|
Loading…
Add table
Reference in a new issue