diff --git a/install.sh b/install.sh index b22726c..7e09042 100644 --- a/install.sh +++ b/install.sh @@ -23,36 +23,70 @@ function system_status() { echo -n "๐Ÿ“ฆ Docker: " if command -v docker &>/dev/null; then echo -e "${GREEN}Installed${NC}" + docker_status="ok" else echo -e "${RED}Missing${NC}" + docker_status="missing" fi echo -n "๐Ÿณ Docker Compose: " if docker compose version &>/dev/null; then echo -e "${GREEN}Available (v2)${NC}" + compose_status="ok" else echo -e "${RED}Missing or incompatible${NC}" + compose_status="missing" fi echo -n "๐Ÿ“ Project folder '$CLONE_DIR': " if [ -d "$CLONE_DIR" ]; then echo -e "${YELLOW}Exists${NC}" + folder_status="exists" else echo -e "${GREEN}Not present${NC}" + folder_status="missing" fi echo -n "๐Ÿ“ฆ Docker image '$CRON_NAME': " if docker images --format '{{.Repository}}' | grep -q "$CRON_NAME"; then echo -e "${YELLOW}Already built${NC}" + image_status="built" else echo -e "${RED}Not built${NC}" + image_status="missing" fi echo -n "๐Ÿ“ฆ Docker container '$CRON_NAME': " if docker ps -a --format '{{.Names}}' | grep -q "^$CRON_NAME$"; then - echo -e "${YELLOW}Exists${NC}" + echo -e "${RED}Not running${NC}" + container_status="exists" else echo -e "${GREEN}Not running${NC}" + container_status="missing" + fi +} + +function check_and_install_docker() { + if [ "$docker_status" = "missing" ]; then + echo -e "${YELLOW}Installing Docker...${NC}" + apt update + apt install -y docker.io + systemctl enable --now docker + echo -e "${GREEN}โœ… Docker installed.${NC}" + fi + + if [ "$compose_status" = "missing" ]; then + echo -e "${YELLOW}Installing Docker Compose plugin...${NC}" + if apt-cache show docker-compose-plugin &>/dev/null; then + apt install -y docker-compose-plugin + else + mkdir -p ~/.docker/cli-plugins + curl -SL https://github.com/docker/compose/releases/download/v2.27.1/docker-compose-linux-x86_64 \ + -o ~/.docker/cli-plugins/docker-compose + chmod +x ~/.docker/cli-plugins/docker-compose + export PATH="$HOME/.docker/cli-plugins:$PATH" + fi + echo -e "${GREEN}โœ… Docker Compose v2 installed.${NC}" fi } @@ -68,10 +102,41 @@ function menu() { echo "" } -# Insert your previous functions here if needed (clone_and_build, etc.) -# Only showing header and status + menu for this snippet. +function clone_and_build() { + check_and_install_docker -# Start script + if [ "$folder_status" = "exists" ] || [ "$image_status" = "built" ]; then + echo -e "${YELLOW}โš ๏ธ Project folder or image already exists.${NC}" + read -rp "$(echo -e "${YELLOW}๐Ÿ” Do you want to reinstall everything? This will remove old data. [Y/n] ${NC}")" confirm + confirm="${confirm,,}" + if [[ "$confirm" =~ ^(y|yes| )?$ ]]; then + echo -e "${YELLOW}๐Ÿงน Cleaning up...${NC}" + docker rm -f "$CRON_NAME" >/dev/null 2>&1 + docker rmi -f "$CRON_NAME" >/dev/null 2>&1 + rm -rf "$CLONE_DIR" + echo -e "${GREEN}โœ… Cleaned up previous install.${NC}" + else + echo -e "${RED}โŒ Installation aborted.${NC}" + return + fi + fi + + echo -e "${GREEN}๐Ÿ“ฅ Cloning repo...${NC}" + git clone "$REPO_URL" "$CLONE_DIR" + cd "$CLONE_DIR" || exit 1 + echo -e "${GREEN}๐Ÿ”ง Building Docker image...${NC}" + docker compose build + + echo -e "${YELLOW}๐Ÿ“จ Enter your Telegram bot token:${NC}" + read -rp "๐Ÿ”‘ TELEGRAM_TOKEN: " token + echo -e "${YELLOW}๐Ÿ‘ฅ Enter your Telegram chat ID:${NC}" + read -rp "๐Ÿ†” TELEGRAM_CHAT_ID: " chat_id + sed -i "s|^TELEGRAM_TOKEN = .*|TELEGRAM_TOKEN = \"$token\"|" bot.py + sed -i "s|^CHAT_ID = .*|CHAT_ID = \"$chat_id\"|" bot.py + echo -e "${GREEN}โœ… Credentials updated in bot.py${NC}" +} + +# --- script start --- clear banner system_status