File size: 6,658 Bytes
7adf043 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | #!/bin/bash
# Smart Academic Report Generator - Installation Script
# Automated setup for the report generation system
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Banner
echo -e "${BLUE}"
cat << "EOF"
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β π Smart Academic Report Generator β
β Professional PhD-Level Reports Installer β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
EOF
echo -e "${NC}"
# Check if running with bash
if [ -z "$BASH_VERSION" ]; then
echo -e "${RED}β This script must be run with bash${NC}"
exit 1
fi
echo -e "${CYAN}Starting installation...${NC}\n"
# Step 1: Check Node.js
echo -e "${YELLOW}[1/6]${NC} Checking Node.js installation..."
if command -v node &> /dev/null; then
NODE_VERSION=$(node --version)
echo -e "${GREEN}β
Node.js is installed: $NODE_VERSION${NC}"
# Check version
REQUIRED_VERSION="16.0.0"
CURRENT_VERSION=$(node --version | cut -d'v' -f2)
if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$CURRENT_VERSION" | sort -V | head -n1)" = "$REQUIRED_VERSION" ]; then
echo -e "${GREEN} Version is compatible (>= v16.0.0)${NC}"
else
echo -e "${YELLOW} β οΈ Version might be too old. Recommended: >= v16.0.0${NC}"
fi
else
echo -e "${RED}β Node.js is not installed${NC}"
echo -e "${YELLOW} Please install Node.js from: https://nodejs.org/${NC}"
exit 1
fi
# Step 2: Check npm
echo -e "\n${YELLOW}[2/6]${NC} Checking npm installation..."
if command -v npm &> /dev/null; then
NPM_VERSION=$(npm --version)
echo -e "${GREEN}β
npm is installed: v$NPM_VERSION${NC}"
else
echo -e "${RED}β npm is not installed${NC}"
echo -e "${YELLOW} npm should come with Node.js. Please reinstall Node.js${NC}"
exit 1
fi
# Step 3: Install docx package
echo -e "\n${YELLOW}[3/6]${NC} Installing docx package..."
if npm list -g docx &> /dev/null; then
echo -e "${GREEN}β
docx is already installed globally${NC}"
else
echo -e "${CYAN} Installing docx globally...${NC}"
if npm install -g docx; then
echo -e "${GREEN}β
docx installed successfully${NC}"
else
echo -e "${YELLOW} β οΈ Global install failed. Trying local install...${NC}"
if npm install docx; then
echo -e "${GREEN}β
docx installed locally${NC}"
else
echo -e "${RED}β Failed to install docx${NC}"
exit 1
fi
fi
fi
# Step 4: Verify required files
echo -e "\n${YELLOW}[4/6]${NC} Verifying required files..."
REQUIRED_FILES=(
"generate-academic-report.js"
"sample-config.json"
"package.json"
"README.md"
"QUICKSTART.md"
"index.html"
)
MISSING_FILES=0
for file in "${REQUIRED_FILES[@]}"; do
if [ -f "$file" ]; then
echo -e "${GREEN} β
$file${NC}"
else
echo -e "${RED} β Missing: $file${NC}"
MISSING_FILES=$((MISSING_FILES + 1))
fi
done
if [ $MISSING_FILES -gt 0 ]; then
echo -e "${RED}\nβ $MISSING_FILES required file(s) missing${NC}"
echo -e "${YELLOW} Please ensure all files are in the current directory${NC}"
exit 1
fi
# Step 5: Create output directory
echo -e "\n${YELLOW}[5/6]${NC} Setting up output directory..."
OUTPUT_DIR="/mnt/user-data/outputs"
if [ -d "$OUTPUT_DIR" ]; then
echo -e "${GREEN}β
Output directory exists: $OUTPUT_DIR${NC}"
else
echo -e "${CYAN} Creating output directory...${NC}"
if mkdir -p "$OUTPUT_DIR" 2>/dev/null; then
echo -e "${GREEN}β
Output directory created${NC}"
else
echo -e "${YELLOW} β οΈ Could not create $OUTPUT_DIR${NC}"
echo -e "${YELLOW} Will use current directory instead${NC}"
OUTPUT_DIR="./outputs"
mkdir -p "$OUTPUT_DIR"
fi
fi
# Make scripts executable
echo -e "\n${YELLOW}[6/6]${NC} Setting file permissions..."
chmod +x generate-academic-report.js 2>/dev/null
chmod +x test-suite.js 2>/dev/null
echo -e "${GREEN}β
Permissions set${NC}"
# Success summary
echo -e "\n${GREEN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo -e "${GREEN}β β${NC}"
echo -e "${GREEN}β β
Installation completed successfully! β${NC}"
echo -e "${GREEN}β β${NC}"
echo -e "${GREEN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
# Next steps
echo -e "\n${CYAN}π Next Steps:${NC}\n"
echo -e "${YELLOW}1.${NC} Test the installation:"
echo -e " ${CYAN}node generate-academic-report.js --config sample-config.json${NC}\n"
echo -e "${YELLOW}2.${NC} Run the test suite:"
echo -e " ${CYAN}node test-suite.js${NC}\n"
echo -e "${YELLOW}3.${NC} Create your first report:"
echo -e " ${CYAN}cp sample-config.json my-config.json${NC}"
echo -e " ${CYAN}# Edit my-config.json with your details${NC}"
echo -e " ${CYAN}node generate-academic-report.js --config my-config.json${NC}\n"
echo -e "${YELLOW}4.${NC} Open HTML interface:"
echo -e " ${CYAN}Open index.html in your web browser${NC}\n"
echo -e "${CYAN}π Documentation:${NC}"
echo -e " β’ README.md - Complete documentation"
echo -e " β’ QUICKSTART.md - Quick reference guide"
echo -e " β’ EXAMPLES.md - Usage examples & tutorials"
echo -e "\n${CYAN}π Happy Report Writing!${NC}\n"
# Optional: Run test
echo -e "${YELLOW}Would you like to run a test now? (y/n)${NC} "
read -r -n 1 response
echo
if [[ "$response" =~ ^[Yy]$ ]]; then
echo -e "\n${CYAN}Running test...${NC}\n"
node test-suite.js
if [ $? -eq 0 ]; then
echo -e "\n${GREEN}β
Test passed! You're ready to generate reports.${NC}\n"
else
echo -e "\n${RED}β Test failed. Please check the error messages above.${NC}\n"
fi
else
echo -e "${YELLOW}Skipping test. Run 'node test-suite.js' anytime to verify.${NC}\n"
fi
exit 0
|