diff --git a/bb.sh b/bb.sh index 67c5179..1b9f5e6 100755 --- a/bb.sh +++ b/bb.sh @@ -152,8 +152,6 @@ global_variables() { # The locale to use for the dates displayed on screen (not for the timestamps) date_format="%B %d, %Y" 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 @@ -184,8 +182,7 @@ google_analytics() { # # $1 the file to edit edit() { - # timestamp="$(date -r $1 +'%Y%m%d%k%M')" - timestamp="$(stat -f "%Sm" -t '%Y%m%d%k%M' $1)" + timestamp="$(date -r $1 +'%Y%m%d%k%M')" $EDITOR "$1" touch -t $timestamp "$1" } @@ -246,11 +243,9 @@ create_html_page() { echo "$title" >> "$filename" echo '' >> "$filename" if [ "$timestamp" == "" ]; then - # echo '
'$(LC_ALL=date_locale date +"$date_format")' — ' >> "$filename" - echo '
'$(date "$date_R")' — ' >> "$filename" + echo '
'$(LC_ALL=date_locale date +"$date_format")' — ' >> "$filename" else - # echo '
'$(LC_ALL=date_locale date +"$date_format" --date="$timestamp") ' — ' >> "$filename" - echo '
'"$timestamp"' — ' >> "$filename" + echo '
'$(LC_ALL=date_locale date +"$date_format" --date="$timestamp") ' — ' >> "$filename" fi echo "$global_author
" >> "$filename" echo '' >> "$filename" # This marks the text body, after the title, date... @@ -381,8 +376,7 @@ all_posts() { title="$(awk '/

/, /<\/a><\/h3>/{if (!/

/ && !/<\/a><\/h3>/) print}' $i)" echo -n '
  • '$title' —' >> "$contentfile" # Date - #date="$(LC_ALL=date_locale date -r "$i" +"$date_format")" - date="$(stat -f "%Sm" -t "%a, %d %h %Y %H:%M:%S %z")" + date="$(LC_ALL=date_locale date -r "$i" +"$date_format")" echo " $date
  • " >> "$contentfile" done echo "" @@ -441,7 +435,7 @@ list_posts() { n=1 for i in $(ls -t *.html); do if [ "$i" == "$index_file" ] || [ "$i" == "$archive_index" ]; then continue; fi - line="$n # $(awk '/

    /, /<\/a><\/h3>/{if (!/

    / && !/<\/a><\/h3>/) print}' $i) # $(stat -f "%Sm" -t "%a, %d %h %Y %H:%M:%S %z" $i)" + line="$n # $(awk '/

    /, /<\/a><\/h3>/{if (!/

    / && !/<\/a><\/h3>/) print}' $i) # $(LC_ALL=date_locale date -r $i +"date_format")" lines="${lines}""$line""\n" # Weird stuff needed for the newlines n=$(( $n + 1 )) done @@ -460,8 +454,8 @@ make_rss() { echo '' >> "$rssfile" echo ''$global_title''$global_url'' >> "$rssfile" echo ''$global_description'en' >> "$rssfile" - echo ''$(date "$date_R")'' >> "$rssfile" - echo ''$(date "$date_R")'' >> "$rssfile" + echo ''$(date -R)'' >> "$rssfile" + echo ''$(date -R)'' >> "$rssfile" echo '' >> "$rssfile" n=0 @@ -477,9 +471,8 @@ make_rss() { echo "]]>$global_url/$i" >> "$rssfile" echo "$global_url/$i" >> "$rssfile" echo "$global_author" >> "$rssfile" + echo ''$(date -r "$i" -R)'' >> "$rssfile" - #echo ''$(date -r "$i" -R)'' >> "$rssfile" - echo ''$(stat -f "%Sm" -t "%a, %d %h %Y %H:%M:%S %z" "$i" )'' >> "$rssfile" n=$(( $n + 1 )) done @@ -575,13 +568,11 @@ rebuild_all_entries() { awk '//, //{if (!// && !//) print}' "$i" >> "$contentfile" # 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" # keep the original timestamp! - #timestamp="$(date -r $i +'%Y%m%d%k%M')" - timestamp="$(stat -f "%Sm" -t '%Y%m%d%k%M' $i)" + timestamp="$(date -r $i +'%Y%m%d%k%M')" mv "$i.rebuilt" "$i" chmod 644 "$i" touch -t $timestamp "$i" @@ -621,14 +612,31 @@ reset() { 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 # Encapsulated on its own function for readability purposes # # $1 command to run # $2 file name of a draft to continue editing (optional) do_main() { + # Detect if using BSD date or GNU date + date_version_detect # Use config file or fallback to inline configuration - source "$global_config" || global_variables + source "$global_config" &> /dev/null || global_variables # Check for $EDITOR if [[ -z "$EDITOR" ]]; then @@ -663,8 +671,8 @@ do_main() { # We're going to back up just in case ls *.html &> /dev/null if [[ $? -eq 0 ]]; then - tar cfz ".backup.tar.gz" *.html - chmod 600 ".backup.tar.gz" + tar cfz ".backup.tar.gz" *.html + chmod 600 ".backup.tar.gz" fi if [ "$1" == "reset" ]; then