Report / install.sh
salekml's picture
Upload 7 files
7adf043 verified
#!/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