1 
 2 
 3 
 4 
 5 
 6 
 7 
 8 
 9 
10 
11 
12 
13 buildFile="$HOME/public_html/random.html"
14 
15 
16 pagesDir="pages"
17 pagesPath="$HOME/public_html/$pagesDir"
18 
19 
20 if [ ! -d "$pagesPath" ]; then
21   echo "Directory not found: $pagesPath"
22   exit 1
23 fi
24 
25 
26 echo "Building $buildFile..."
27 
28 echo "<!DOCTYPE html>
29 <html>
30 <head>
31 <meta charset=\"utf-8\">
32 <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">
33 <title>Redirecting...</title>
34 <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">
35 </head>
36 <body>
37   <script>
38     var pageList = [" > "$buildFile"
39 
40 
41 
42 
43 for page in "$pagesPath"/*; do
44   if [ -f "$page" ] && [ "${page##*.}" == "html" ]; then
45     echo "      \"$( echo $page | awk -F '/' '{print $6}' )\"," >> "$buildFile"
46   fi
47 done
48 
49 
50 echo "    ];
51     var randPage = Math.floor(Math.random() * pageList.length);
52     window.location = \"$pagesDir/\" + pageList[randPage];
53   </script>
54 </body>
55 </html>" >> "$buildFile"
56 
57 echo "Done."