#!/bin/bash ### Title: MicroBlogger 1.9 ### Author: Bowie J. Poag ### Modified: 070603:1046 ### #### Modified GZB 03-03-2004 ### ### WARNING: THIS SCRIPT MAY ATTEMPT TO REWRITE PORTIONS OF ITSELF. ### ### ### Any changes you make may undermine MicroBlogger's ability to ### correctly self-modify, causing this script to backfire, detonate, ### and harm small children. Worse, it will soil your reputation. ### ### Rather than firing up your chainsaw and slaughtering my code to ### smithereens, it may be a better idea to simply suggest new ### features to the author (me) via MicroBlogger's development page. ### ### ### WARNING: THIS SCRIPT MAY ATTEMPT TO REWRITE PORTIONS OF ITSELF. export bordertrim="+-----------------------------------------------------------------+" function menubanner { echo "|,$bannertitle" >foo echo "" echo " $bordertrim" cat foo | awk -F, '{printf(" %1s %46s %1s\n", "| MicroBlogger 1.9", $2, $1)}' echo " $bordertrim" rm -rf foo } function addnews { export bannertitle="Add A News Item" menubanner rm -rf .scratch echo " " echo " Enter The Subject Of This News Item. " echo -n " : "; read subject echo echo " Your avatars are.." echo cat avatars.txt | awk '{printf("%10s %50s\n", $1,$2)}' echo " " echo " Which avatar should be used?" echo -n " : "; read whichav echo echo -n " Got it! Hit ENTER to add the news." read shit pico .description if [ -f news0.txt ]; then cat news0.txt >>archive.txt; rm -rf .x rm -rf news0.txt fi if [ -f news1.txt ]; then mv news1.txt news0.txt fi if [ -f news2.txt ]; then mv news2.txt news1.txt fi if [ -f news3.txt ]; then mv news3.txt news2.txt fi if [ -f news4.txt ]; then mv news4.txt news3.txt fi if [ -f news5.txt ]; then mv news5.txt news4.txt fi if [ -f news6.txt ]; then mv news6.txt news5.txt fi if [ -f news7.txt ]; then mv news7.txt news6.txt fi if [ -f news8.txt ]; then mv news8.txt news7.txt fi if [ -f news9.txt ]; then mv news9.txt news8.txt fi echo -n " Adding News! (This may take a while..)"; echo "
$subject

`cat .description`

(Added on `date +"%A, %B %d, %C%y @ %r"`)

">news9.txt echo -n ".."; cat news9.txt news8.txt news7.txt news6.txt news5.txt news4.txt news3.txt news2.txt news1.txt news0.txt >news.txt cat news9.txt $whichav-archive.txt >.x ; mv .x $whichav-archive.txt; echo -n "."; rm -rf .description echo -n "."; rm -rf .foo echo -n "."; rm -rf .temp echo "...[ OK ]"; } function removenews { export bannertitle="Remove A News Item" menubanner echo " Ok..Here's a list of news items currently on your blog:"; item=10; echo " " for i in 9 8 7 6 5 4 3 2 1 0 do item=`echo $item-1 | bc`; echo " Item $item) `cat news$i.txt | head -n1 | cut -c100- | cut -d\< -f1` " done echo " "; echo -n " Which item would you like to remove? [0-9, x to Exit] : "; dchoice=""; read dchoice if [[ dchoice -eq "x" ]]; then clear; microblogger; fi echo " "; echo -n " Removing article $dchoice.."; rm -rf news$dchoice.txt; touch news$dchoice.txt; echo -n "."; cat news9.txt news8.txt news7.txt news6.txt news5.txt news4.txt news3.txt news2.txt news1.txt news0.txt >news.txt echo -n ".. [ OK ]"; } function editnews { export bannertitle="Edit A News Item" menubanner echo " "; echo " Here's a list of news items currently on your blog:"; item=10; echo " " for i in 9 8 7 6 5 4 3 2 1 0 do item=`echo $item-1 | bc`; echo " Item $item) `cat news$i.txt | head -n1 | cut -c100- | cut -d\< -f1` " done echo " "; echo -n " Which item would you like to edit? [0-9, x to Exit] : "; achoice=""; read achoice if [[ achoice -eq "x" ]]; then clear; achoice=""; return; fi pico news$achoice.txt; cat news9.txt news8.txt news7.txt news6.txt news5.txt news4.txt news3.txt news2.txt news1.txt news0.txt >news.txt } function editavatar { export bannertitle="Edit An Avatar" menubanner echo printf " Avatar:%40s Filename:\n" cat avatars.txt | awk '{printf("%10s %50s\n", $1, $2)}' echo echo " Which avatar do you want to modify?" echo -n " : " read editavatar echo echo " Enter the NEW filename (or URL) for this avatar's image:" echo -n " : " read newfilename echo echo -n " Are you sure you want to make this change? [y/N] : " read avatarchange if [ "$avatarchange" = "y" ]; then cat avatars.txt | grep -v $editavatar >.tmp echo "$editavatar $newfilename" >>.tmp cat .tmp >avatars.txt rm -rf .tmp echo " " fi } function deleteavatar { export bannertitle="Delete An Avatar" menubanner printf " Avatar:%40s Filename:\n" cat avatars.txt | awk '{printf("%10s %50s\n", $1, $2)}' echo echo " Enter the NAME (not the filename!) of the avatar you want to remove." echo -n " : " read delavatar echo echo -n " Are you sure? [y/N] : " read avatarkill if [ "$avatarkill" = "y" ]; then cat avatars.txt | grep -v $delavatar >avatars.txt echo " " fi } function listavatars { export bannertitle="List All Avatars" menubanner echo " Here are all the avatars currently defined:" echo cat avatars.txt | awk '{printf("%10s %50s\n", $1, $2)}' } function addavatar { export bannertitle="Add An Avatar" menubanner echo echo " Enter the name you'de like to give this avatar. Dont use spaces! :)" echo -n " : " read avatar echo echo " Mmkay..Now give me the image filename (or URL) for this avatar." echo -n " : " read avatarimage echo " " echo "$avatar $avatarimage" >>avatars.txt; touch $avatar-archive.txt; sed -e "s/FOO/$avatar/g" archive-template.shtml > $avatar-archive.shtml echo "Archive created for $avatar"; echo " " } function addlink { export bannertitle="Add A Link" menubanner echo echo -n " Enter The Name Of This Link (NOT The URL!): " read name echo -n " Mmkay..Enter URL: " read link echo -n " Now Enter A Description Of This Link: " read desc echo "$name $desc ">>links.txt echo "" >>links.txt echo echo " Done." echo } function addwelcome { export bannertitle="Add A Welcome Message" menubanner rm -rf .scratch echo " "; echo " Enter The Title Of Your Welcome (ex. Welcome To Foo!)" echo -n " :" read subject echo -n " Hit ENTER to add the welcome text!" read shit pico .description if [ -f welcome.txt ]; then rm -rf welcome.txt fi echo "
$subject

...`cat .description`

(Added on `date +"%A, %B %d, %C%y @ %r"`)

">welcome.txt } function sanitycheck { echo -n " You selected $choice.. Is this correct? [Y/n] or ENTER: "; read ask if [ "$ask" = "y" ]; then clear; fi if [ "$ask" = "n" ]; then clear choice=""; microblogger; fi clear } function cleararchive { clear; echo " "; echo -n " Destroying news archive..." rm -rf archive.txt } function randomsnapshot { cd snapshots export TRIGGER="0" while [ "$TRIGGER" -ne 1 ] do export RAND="$RANDOM" export PILE=`ls -l | wc -l` if [ "$RAND" -le "$PILE" ] then export TRIGGER="1" fi done export RANDOMSNAPSHOT=`ls -l | sed -n "$RAND"p | tail -1 | awk '{print $9}' | cut -d. -f1` cd .. } function microblogger { echo "" echo " +-----------------------------------------------------------------+"; echo " | MicroBlogger 1.9 Copyright @ 2002 Bowie J. Poag |"; echo " +-----------------------------------------------------------------+"; echo " "; echo " 1) Add A News Item 10) Add An Avatar"; echo " 2) Edit A News Item 11) Edit An Avatar"; echo " 3) Add A Welcome Message 12) Delete An Avatar"; echo " 4) Edit The Welcome Message 13) List All Avatars"; echo " 5) Remove A News Item"; echo " 6) Add A Site To The Links Section"; echo " 7) Edit The Links Section"; echo " 8) Edit News Archive"; echo " 9) Clear News Archive"; echo " "; echo " x) Quit MicroBlogger"; echo " "; echo -n " Your choice [1-13,x] : "; choice=""; read choice if [[ "$choice" -eq "x" ]]; then echo; exit fi sanitycheck case $choice in 1) addnews ;; 2) editnews ;; 3) addwelcome ;; 4) pico welcome.txt ;; 5) removenews ;; 6) addlink ;; 7) pico links.txt ;; 8) pico archive.txt ;; 9) cleararchive ;; 10) addavatar ;; 11) editavatar ;; 12) deleteavatar ;; 13) listavatars ;; x) exit ;; *) echo ;; esac } while true do clear microblogger echo " "; echo -n " [ Press ENTER To Return To Main Menu ] "; read smack done