init 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #!/bin/bash
  2. username=""
  3. title=""
  4. fname=""
  5. editor=""
  6. #Prompt user for basic information
  7. if [ ! -d "public_html" ]; then
  8. echo "Welcome to nci webscript! Let's start!"
  9. else
  10. yn=""
  11. while true; do
  12. echo "nci is already initialized, so if you continue, you'd be only updating your configuration files. Do you want to change nci configuration? (y/n):"
  13. read -r yn
  14. case $yn in
  15. [Yy]* ) echo "Okay, let's continue then..."
  16. break
  17. ;;
  18. [Nn]* ) echo "Operation cancelled."
  19. exit 1
  20. ;;
  21. * ) echo "Error: Please answer just y/n.";;
  22. esac
  23. done
  24. fi
  25. echo "Please tell me, what's your neocities.org username? (just your username, I don't need the whole URL):"
  26. read -r username
  27. while [ -z "$username" ]; do
  28. echo "Dude, you just typed nothing. Please try again:"
  29. read -r username
  30. done
  31. if [ ! -d "public_html" ]; then
  32. echo "Okay, now please give your blog a name (i.e.: \"jane doe's super fuckin awesome blog\"):"
  33. read -r title
  34. while [ -z "$title" ]; do
  35. echo "No ideas? Don't worry, just type any crap for now (you'll be able to change your blog title whenever you want by editing the HTML files):"
  36. read -r title
  37. done
  38. fi
  39. echo "Now, I'd like to know: which text editor do you prefer? Type its name here! (lowercase, i.e.: vim, gedit, ...). Leave the line empty to use default (nano):"
  40. read -r editor
  41. if [ -z "$editor" ]; then
  42. editor="nano"
  43. fi
  44. echo "$editor selected as preferred editor. You can change this preference by either editing the \"user.conf\" file or running \"./init\" again."
  45. echo "It's almost done! Please type a filename for your blog html file (lowercase, without \".html\" extension at filename end. If your blog file is your main/index page, just type \"index\"):"
  46. read -r fname
  47. while [ -z "$fname" ]; do
  48. echo "Just type \"index\" if your blog is your main page (If not, try naming it... uhm... \"blog\"?):"
  49. read -r fname
  50. done
  51. echo "Initializing nci webscript for Neocities..."
  52. #Create the entries directory for raw entry data
  53. if [ ! -d "entries" ]; then
  54. mkdir entries
  55. echo "\"entries\" directory created."
  56. else
  57. echo "\"entries\" directory already exists."
  58. fi
  59. #Create the public_html directory
  60. if [ ! -d "public_html" ]; then
  61. mkdir public_html
  62. echo "\"public_html\" directory created."
  63. else
  64. echo "\"public_html\" directory already exists."
  65. fi
  66. #Create the blog html file
  67. if [ ! -f "public_html/$fname.html" ]; then
  68. echo "<!doctype html>
  69. <html>
  70. <head>
  71. <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
  72. <meta name=\"author\" content=\"$username\">
  73. <link rel=\"shortcut icon\" href=\"favicon.ico\">
  74. <link rel=\"stylesheet\" href=\"style.css\">
  75. <title>$title</title>
  76. </head>
  77. <body>
  78. <header>
  79. <center><h1>$title</h1></center>
  80. </header>
  81. <section id=\"about\" align=\"justify\">
  82. <center>This is the $username's neocities blog!</center>
  83. </section>
  84. <hr>
  85. <main>
  86. <section id=\"entries\">
  87. <!-- !!BLOG ENTRIES -->
  88. </section>
  89. </main>
  90. <hr>
  91. <footer>
  92. <center>- <a href=\"rss.xml\">RSS</a> -</center>
  93. </footer>
  94. </body>
  95. </html>
  96. " >> "public_html/$fname.html"
  97. echo "\"public_html/$fname.html\" file created."
  98. else
  99. echo "\"public_html/$fname.html\" file already exists."
  100. fi
  101. #Create the blog RSS feed
  102. if [ ! -f "public_html/rss.xml" ]; then
  103. echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>
  104. <rss version=\"2.0\" xmlns:atom=\"https://www.w3.org/2005/Atom/\">
  105. <channel>
  106. <title>$title - RSS feed</title>
  107. <link>https://$username.neocities.org/</link>
  108. <atom:link href=\"https://$username.neocities.org/rss.xml\" rel=\"self\" type=\"application/rss+xml\"/>
  109. <description>This is the $username's blog RSS feed.</description>
  110. <language>en-us</language>
  111. <ttl>1000</ttl>
  112. <!-- !!BLOG ENTRIES -->
  113. </channel>
  114. </rss>
  115. " >> public_html/rss.xml
  116. echo "\"public_html/rss.xml\" file created."
  117. else
  118. echo "\"public_html/rss.xml\" file already exists."
  119. fi
  120. #Create style file for the blog page
  121. if [ ! -f "public_html/style.css" ]; then
  122. echo "/* Write some nice CSS rules for your blog here... */" >> public_html/style.css
  123. else
  124. echo "\"public_html/style.css\" file already exists."
  125. fi
  126. #Create entries warning file
  127. if [ ! -f "entries/README" ]; then
  128. echo "DO NOT DELETE ANY FILE FROM THIS DIRECTORY (EVEN FILES THAT BELONG TO DELETED ENTRIES). DO NOT DELETE THIS FILE EITHER." >> entries/README
  129. fi
  130. #Create articles directory for entries html files
  131. if [ ! -d "public_html/articles" ]; then
  132. mkdir "public_html/articles"
  133. echo "\"public_html/articles\" directory created."
  134. else
  135. echo "\"public_html/articles\" directory already exists."
  136. fi
  137. #Create new HTML template file for articles (DO NOT DELETE IT)
  138. if [ ! -f "public_html/articles/article_template.html" ]; then
  139. touch "public_html/articles/article_template.html"
  140. echo "<!doctype html>
  141. <html>
  142. <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
  143. <meta name=\"author\" content=\"$username\">
  144. <link rel=\"shortcut icon\" href=\"favicon.ico\">
  145. <link rel=\"stylesheet\" href=\"style.css\">
  146. <!-- article title is inserted next to the title tag, you can delete this line if you want -->
  147. <title> - $title</title>
  148. </head>
  149. <body>
  150. <hr>
  151. <main>
  152. <!-- !!ARTICLE -->
  153. </main>
  154. <hr>
  155. <footer>
  156. <center>
  157. <a href=\"../$fname.html\">go back</a>
  158. </center>
  159. </footer>
  160. </body>
  161. </html>
  162. " >> public_html/articles/article_template.html
  163. echo "\"public_html/articles/article_template.html\" file created (DO NOT DELETE IT!)"
  164. else
  165. echo "\"public_html/articles/article_template.html\" file already exists."
  166. fi
  167. #Create css style for articles
  168. if [ ! -f "public_html/articles/style.css" ]; then
  169. touch "public_html/articles/style.css"
  170. echo "/* WRITE SOME CSS RULES FOR YOUR ARTICLES HERE */" >> public_html/articles/style.css
  171. echo "\"public_html/articles/style.css\" file created."
  172. else
  173. echo "\"public_html/articles/style.css\" file already exists."
  174. fi
  175. #Create configuration file (DO NOT DELETE IT)
  176. if [ ! -f "nci.conf" ]; then
  177. echo "$username
  178. $fname
  179. " >> nci.conf
  180. echo "Configuration file (\"nci.conf\") created! (DO NOT DELETE IT!)"
  181. else
  182. echo "Configuration file already exists. Updating it..."
  183. rm -f "nci.conf"
  184. touch "nci.conf"
  185. echo "$username
  186. $fname
  187. " >> nci.conf
  188. echo "Configuration file updated."
  189. fi
  190. #Create preferences file (DO NOT DELETE IT)
  191. if [ ! -f "user.conf" ]; then
  192. echo "$editor" >> user.conf
  193. echo "Preferences file (\"prefs.conf\") created! (DO NOT DELETE IT!)"
  194. else
  195. echo "Preferences file already exists. Updating it..."
  196. rm -f "user.conf"
  197. touch "user.conf"
  198. echo "$editor" >> user.conf
  199. echo "Preferences file updated."
  200. fi
  201. #Create excluded articles file (DO NOT DELETE IT)
  202. if [ ! -f "exclude.conf" ]; then
  203. touch "exclude.conf"
  204. echo "exclude.conf file created! (DO NOT DELETE IT!)"
  205. else
  206. echo "exclude.conf file already exists"
  207. fi
  208. echo "IMPORTANT: Your generated HTML files contain some <!-- COMMENTS LIKE THIS ONE --> that nci system requires to work properly. DO NOT DELETE THEM UNLESS OTHERWISE NOTED."
  209. echo "OK."