-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
148 lines (121 loc) · 3.31 KB
/
install.sh
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
#!/bin/bash
# Colors
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'
# Check root access
if [[ $EUID -ne 0 ]]; then
echo -e "${red}Error: ${plain} Please run with root privileges \n "
exit 1
fi
check_docker() {
if ! command -v docker &> /dev/null; then
echo -e "${yellow}Docker is not installed. Installing Docker...${plain}"
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
systemctl start docker
systemctl enable docker
fi
}
check_dependencies() {
echo -e "${yellow}Checking system dependencies...${plain}"
# Install git if not present
if ! command -v git &> /dev/null; then
apt-get update
apt-get install -y git
fi
# Install Python and pip if not present
if ! command -v python3 &> /dev/null; then
apt-get update
apt-get install -y python3 python3-pip
fi
# Ensure pip3 is installed
if ! command -v pip3 &> /dev/null; then
echo -e "${red}pip3 not found! Installing...${plain}"
apt-get install -y python3-pip
fi
}
download_project() {
echo -e "${yellow}Downloading project files...${plain}"
# Ensure clean directory
if [[ -d /usr/local/scanner ]]; then
echo -e "${yellow}Cleaning existing directory...${plain}"
rm -rf /usr/local/scanner
fi
mkdir -p /usr/local/scanner
cd /usr/local/scanner || exit 1
# Clone repository
git clone https://github.com/mohamadm0meni/OSG-SCAN.git .
if [[ $? -ne 0 ]]; then
echo -e "${red}Repository cloning failed${plain}"
return 1
fi
# Ensure Dockerfile exists
if [[ ! -f Dockerfile ]]; then
echo -e "${red}Dockerfile not found in cloned repository!${plain}"
ls -lah
exit 1
fi
# Install Python dependencies
if [[ -f requirements.txt ]]; then
pip3 install -r requirements.txt
else
echo -e "${red}requirements.txt not found!${plain}"
return 1
fi
# Set permissions
if [[ -f main.py ]]; then
chmod +x main.py
else
echo -e "${red}main.py not found!${plain}"
return 1
fi
return 0
}
setup_docker() {
echo -e "${yellow}Setting up Docker environment...${plain}"
# Build Docker image
docker build -t osgscan .
# Create executable script
cat > /usr/local/bin/osgscan << 'EOF'
#!/bin/bash
docker run --rm \
--network host \
-v $(pwd):/app/data \
osgscan "$@"
EOF
chmod +x /usr/local/bin/osgscan
}
create_service() {
cat > /etc/systemd/system/scanner.service << EOF
[Unit]
Description=Scanner Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/scanner/main.py
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable scanner
systemctl start scanner
}
main() {
echo -e "${green}Starting installation...${plain}"
check_dependencies
check_docker
if download_project; then
setup_docker
create_service
echo -e "${green}Installation completed successfully!${plain}"
echo -e "You can now use 'osgscan' command or check service status with 'systemctl status scanner'"
else
echo -e "${red}Installation failed${plain}"
exit 1
fi
}
main