11#! /bin/bash
22
3- # Portfolio Generator Installation Script
4-
5- # Exit on error
6- set -e
7-
8- # Define colors for output
9- GREEN=' \033[0;32m'
10- YELLOW=' \033[1;33m'
11- RED=' \033[0;31m'
12- NC=' \033[0m' # No Color
13-
14- echo -e " ${YELLOW} Portfolio Generator Installation${NC} "
15- echo " This script will install the Portfolio Generator and set it up to run automatically."
16- echo
17-
18- # Check Python version
19- echo -e " ${YELLOW} Checking Python version...${NC} "
20- if command -v python3 & > /dev/null; then
21- python_version=$( python3 --version)
22- echo -e " ${GREEN} Found $python_version ${NC} "
23- else
24- echo -e " ${RED} Python 3 is not installed. Please install Python 3.6 or newer.${NC} "
25- exit 1
26- fi
27-
28- # Create directory
29- echo -e " ${YELLOW} Creating project directory...${NC} "
30- read -p " Enter directory path for installation [./portfolio-generator]: " install_dir
31- install_dir=${install_dir:- ./ portfolio-generator}
32-
33- mkdir -p " $install_dir "
34- cd " $install_dir "
35- echo -e " ${GREEN} Created directory: $install_dir ${NC} "
3+ # Adres projektu i główny skrypt
4+ PROJECT_URL=" https://raw.githubusercontent.com/DevOpsTerminal/hello/main"
5+ SCRIPT_NAME=" hello.sh"
6+ CHECKSUM_NAME=" checksums.sha256"
7+
8+ # Funkcja do logowania z kolorami
9+ log_error () {
10+ echo -e " \e[31m[BŁĄD]\e[0m $1 " >&2
11+ }
3612
37- # Download script
38- echo -e " ${YELLOW} Downloading portfolio generator script...${NC} "
39- wget -O portfolio_generator.py https://raw.githubusercontent.com/yourusername/portfolio-generator/main/portfolio_generator.py || {
40- echo -e " ${RED} Failed to download script. Creating a new one from your clipboard...${NC} "
41- echo " Please paste the script content and press Ctrl+D when finished:"
42- cat > portfolio_generator.py
13+ log_success () {
14+ echo -e " \e[32m[SUKCES]\e[0m $1 "
4315}
44- chmod +x portfolio_generator.py
45- echo -e " ${GREEN} Script saved to portfolio_generator.py${NC} "
4616
47- # Create domains.txt
48- echo -e " ${YELLOW} Creating domains.txt file...${NC} "
49- if [ ! -f domains.txt ]; then
50- echo " Please enter domain names (one per line). Press Ctrl+D when finished:"
51- cat > domains.txt
52- echo -e " ${GREEN} Created domains.txt with your domains${NC} "
53- else
54- echo -e " ${GREEN} domains.txt already exists${NC} "
55- fi
17+ log_info () {
18+ echo -e " \e[34m[INFO]\e[0m $1 "
19+ }
5620
57- # Install dependencies
58- echo -e " ${YELLOW} Installing Python dependencies...${NC} "
59- pip3 install --user requests beautifulsoup4 scikit-learn numpy pillow schedule gitpython
60- echo -e " ${GREEN} Dependencies installed${NC} "
21+ # Funkcja pobierająca i weryfikująca sumę kontrolną
22+ download_and_verify () {
23+ # Pobierz sumę kontrolną
24+ log_info " Pobieranie sumy kontrolnej..."
25+ local remote_checksum=$( curl -sSL " ${PROJECT_URL} /${CHECKSUM_NAME} " | grep " ${SCRIPT_NAME} " | awk ' {print $1}' )
6126
62- # Create output directory
63- mkdir -p portfolio
27+ if [ -z " $remote_checksum " ]; then
28+ log_error " Nie udało się pobrać sumy kontrolnej!"
29+ return 1
30+ fi
6431
65- # Create systemd service file
66- echo -e " ${YELLOW} Setting up automatic execution ...${NC} "
67- read -p " Do you want to set up a systemd service to run the script automatically? (y/n) " setup_systemd
32+ # Pobierz skrypt
33+ log_info " Pobieranie skryptu instalacyjnego ..."
34+ curl -sSL " ${PROJECT_URL} / ${SCRIPT_NAME} " > " ${SCRIPT_NAME} "
6835
69- if [ " $setup_systemd " = " y" ] || [ " $setup_systemd " = " Y" ]; then
70- username=$( whoami)
71- current_dir=$( pwd)
72-
73- cat > portfolio-generator.service << EOF
74- [Unit]
75- Description=Portfolio Generator Service
76- After=network.target
36+ # Sprawdź sumę kontrolną
37+ log_info " Weryfikacja sumy kontrolnej..."
38+ local local_checksum=$( sha256sum " ${SCRIPT_NAME} " | awk ' {print $1}' )
7739
78- [Service]
79- Type=simple
80- User=$username
81- WorkingDirectory=$current_dir
82- ExecStart=/usr/bin/python3 $current_dir /portfolio_generator.py
83- Restart=on-failure
84- StandardOutput=syslog
85- StandardError=syslog
86- SyslogIdentifier=portfolio-generator
40+ if [ " $remote_checksum " != " $local_checksum " ]; then
41+ log_error " OSTRZEŻENIE: Suma kontrolna nie zgadza się!"
42+ log_error " Suma zdalna: $remote_checksum "
43+ log_error " Suma lokalna: $local_checksum "
44+ rm " ${SCRIPT_NAME} "
45+ return 1
46+ fi
8747
88- [Install]
89- WantedBy=multi-user.target
90- EOF
91-
92- echo -e " ${GREEN} Created systemd service file: portfolio-generator.service${NC} "
93- echo " To install the service, run the following commands:"
94- echo " sudo cp portfolio-generator.service /etc/systemd/system/"
95- echo " sudo systemctl daemon-reload"
96- echo " sudo systemctl enable portfolio-generator.service"
97- echo " sudo systemctl start portfolio-generator.service"
98- else
99- echo " To set up automatic execution, you can add a cron job:"
100- echo " crontab -e"
101- echo " Then add this line to run daily at 16:00:"
102- echo " 0 16 * * * cd $( pwd) && /usr/bin/python3 portfolio_generator.py"
103- fi
48+ # Nadaj uprawnienia wykonania
49+ chmod +x " ${SCRIPT_NAME} "
50+ log_success " Suma kontrolna zweryfikowana poprawnie!"
10451
105- # Set up Git
106- echo -e " ${YELLOW} Setting up Git repository...${NC} "
107- read -p " Do you want to set up a Git repository? (y/n) " setup_git
52+ # Uruchom skrypt
53+ log_info " Uruchamianie skryptu..."
54+ ./" ${SCRIPT_NAME} "
55+ }
10856
109- if [ " $setup_git " = " y" ] || [ " $setup_git " = " Y" ]; then
110- cd portfolio
111- git init
112- echo " *.log" > .gitignore
113- echo " __pycache__/" >> .gitignore
114- echo " *.py[cod]" >> .gitignore
115- echo " *$py .class" >> .gitignore
116- git add .
117- git commit -m " Initial commit"
118-
119- read -p " Enter remote repository URL (leave empty to skip): " remote_url
120- if [ ! -z " $remote_url " ]; then
121- git remote add origin " $remote_url "
122- echo -e " ${GREEN} Remote repository added: $remote_url ${NC} "
123- echo " To push to remote repository, run:"
124- echo " cd $( pwd) && git push -u origin main"
57+ # Główna logika
58+ main () {
59+ # Sprawdź wymagane narzędzia
60+ for tool in curl sha256sum; do
61+ if ! command -v " $tool " & > /dev/null; then
62+ log_error " Wymagane narzędzie $tool nie jest zainstalowane!"
63+ exit 1
64+ fi
65+ done
66+
67+ # Wykonaj pobieranie i weryfikację
68+ if download_and_verify; then
69+ log_success " Instalacja zakończona sukcesem!"
70+ exit 0
71+ else
72+ log_error " Instalacja nie powiodła się!"
73+ exit 1
12574 fi
126- cd ..
127- echo -e " ${GREEN} Git repository initialized${NC} "
128- fi
129-
130- # Run the script
131- echo -e " ${YELLOW} Running the portfolio generator for the first time...${NC} "
132- read -p " Do you want to run the script now? (y/n) " run_now
133-
134- if [ " $run_now " = " y" ] || [ " $run_now " = " Y" ]; then
135- python3 portfolio_generator.py
136- echo -e " ${GREEN} Script executed! Check the portfolio/index.html file.${NC} "
137- else
138- echo -e " ${GREEN} You can run the script manually with:${NC} "
139- echo " cd $( pwd) && python3 portfolio_generator.py"
140- fi
75+ }
14176
142- echo
143- echo -e " ${GREEN} Installation complete!${NC} "
144- echo " Your portfolio generator is set up in: $install_dir "
145- echo " Generated portfolio will be in: $install_dir /portfolio/index.html"
146- echo
147- echo " Thank you for using Portfolio Generator!"
77+ # Uruchom główną funkcję
78+ main
0 commit comments