First files to the project
This commit is contained in:
commit
cda8eb1232
26 changed files with 2657 additions and 0 deletions
10
scripts/system/alive.sh
Normal file
10
scripts/system/alive.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo '{"progress": 0, "message": "This server is up!!!", "error":0, "code_error": 0, "sucks": 1}'
|
||||
|
||||
sleep 1
|
||||
|
||||
echo '{"progress": 100, "message": "Finishing scripts without errors", "error":0, "code_error": 0, "sucks": 1}'
|
||||
|
||||
exit 0
|
||||
|
||||
29
scripts/system/install_git.sh
Normal file
29
scripts/system/install_git.sh
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/sh
|
||||
|
||||
echo "Installing git"
|
||||
|
||||
echo '{"error": 0, "status": 0, "progress": 0, "no_progress":0, "message": "Installing git..."}'
|
||||
|
||||
sleep 1
|
||||
|
||||
sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y git
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
|
||||
sleep 1
|
||||
|
||||
#echo "Installed git sucessfully if not error..."
|
||||
echo '{"error": 0, "status": 0, "progress": 100, "no_progress":0, "message": "Installed git sucessfully..."}'
|
||||
|
||||
sleep 1
|
||||
|
||||
else
|
||||
|
||||
echo "Sorry, cannot update the server..."
|
||||
|
||||
exit;
|
||||
|
||||
fi
|
||||
|
||||
|
||||
|
||||
19
scripts/system/install_psutil.sh
Normal file
19
scripts/system/install_psutil.sh
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Install pip
|
||||
|
||||
sleep 1
|
||||
|
||||
echo '{"error": 0, "status": 0, "progress": 100, "no_progress":0, "message": "Installing python3-psutil..."}'
|
||||
|
||||
sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y python3-pip
|
||||
|
||||
#sudo pip3 install psutil
|
||||
sudo apt-get install -y python3-psutil
|
||||
|
||||
#echo "Installed python3-psutil sucessfully if not error..."
|
||||
|
||||
sleep 1
|
||||
|
||||
echo '{"error": 0, "status": 0, "progress": 100, "no_progress":0, "message": "Installed python3-psutil sucessfully..."}'
|
||||
|
||||
27
scripts/system/install_python.sh
Normal file
27
scripts/system/install_python.sh
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/sh
|
||||
|
||||
sleep 1
|
||||
|
||||
echo '{"error": 0, "status": 0, "progress": 0, "no_progress":0, "message": "Installing Python..."}'
|
||||
|
||||
sleep 1
|
||||
|
||||
sudo apt-get -y install python3 python3-pip
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
|
||||
#echo "Installed python3 sucessfully if not error..."
|
||||
echo '{"error": 0, "status": 0, "progress": 100, "no_progress":0, "message": "Installed python sucessfully..."}'
|
||||
|
||||
sleep 1
|
||||
|
||||
else
|
||||
|
||||
echo "Sorry, cannot install python..."
|
||||
|
||||
exit 1;
|
||||
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
|
||||
192
scripts/system/install_pzoo_stats.py
Normal file
192
scripts/system/install_pzoo_stats.py
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
#!/usr/bin/python3 -u
|
||||
|
||||
# A script for install pzoo user
|
||||
|
||||
import subprocess
|
||||
import argparse
|
||||
import re
|
||||
import os
|
||||
import shutil
|
||||
import pwd
|
||||
from subprocess import call
|
||||
from pathlib import Path
|
||||
from time import sleep
|
||||
|
||||
parser = argparse.ArgumentParser(description='A script for install leviathan user')
|
||||
|
||||
#parser.add_argument('--url', help='The url where notify updates', required=True)
|
||||
parser.add_argument('--url_stats', help='The url where pastafaristats notify the stats', required=True)
|
||||
parser.add_argument('--user', help='The user for pastafari', required=True)
|
||||
parser.add_argument('--pub_key', help='The pub key used in pastafari user', required=True)
|
||||
parser.add_argument('--group', help='Server group', required=False)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
#url=args.url
|
||||
|
||||
check_url = re.compile(
|
||||
r'^(?:http|ftp)s?://' # http:// or https://
|
||||
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...
|
||||
r'localhost|' #localhost...
|
||||
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
|
||||
r'(?::\d+)?' # optional port
|
||||
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
|
||||
|
||||
print('{"error": 0, "status": 0, "progress": 0, "no_progress":0, "message": "Installing tools for monitoring the server..."}')
|
||||
|
||||
#check_url.match(args.url) and
|
||||
|
||||
if check_url.match(args.url_stats):
|
||||
|
||||
try:
|
||||
u=pwd.getpwnam(args.user)
|
||||
|
||||
if call("sudo userdel -r %s" % args.user, shell=True) > 0:
|
||||
print('Error, user with same username exists and cannot delete of the server')
|
||||
exit(1)
|
||||
else:
|
||||
print('Cleaning user with the same name')
|
||||
|
||||
except:
|
||||
pass
|
||||
|
||||
# Create users
|
||||
|
||||
if call("sudo useradd -m -s /bin/bash %s" % args.user, shell=True) > 0:
|
||||
|
||||
# Delete user with this name, you should not install it in a old server.
|
||||
|
||||
if call("sudo userdel -r %s" % args.user, shell=True) > 0:
|
||||
print('Error, remove the old user')
|
||||
exit(1)
|
||||
else:
|
||||
|
||||
if call("sudo useradd -m -s /bin/sh %s" % args.user, shell=True) > 0:
|
||||
print('Error, cannot add a new user')
|
||||
exit(1)
|
||||
|
||||
else:
|
||||
print('Added user')
|
||||
|
||||
if call("sudo mkdir -p /home/"+args.user+"/.ssh && sudo chown "+args.user+":"+args.user+" /home/"+args.user+"/.ssh && sudo chmod 700 /home/"+args.user+"/.ssh", shell=True) > 0:
|
||||
print('Error, cannot add ssh directory')
|
||||
exit(1)
|
||||
else:
|
||||
print('Added ssh directory')
|
||||
|
||||
if call("sudo cp "+args.pub_key+" /home/"+args.user+"/.ssh/authorized_keys && sudo chown "+args.user+":"+args.user+" /home/"+args.user+"/.ssh/authorized_keys && sudo chmod 600 /home/"+args.user+"/.ssh/authorized_keys", shell=True) > 0:
|
||||
print('Error, cannot pub key to user')
|
||||
exit(1)
|
||||
else:
|
||||
print('Added pub key to user')
|
||||
|
||||
# Edit sudo file
|
||||
|
||||
with open('modules/pastafari2/scripts/system/sudoers.d/spanel') as f:
|
||||
sudoers=f.read()
|
||||
|
||||
with open('/etc/sudoers.d/spanel', 'w') as f:
|
||||
sudoers=sudoers.replace("spanel", args.user)
|
||||
f.write(sudoers)
|
||||
|
||||
# Installing composer things for php alerts...
|
||||
|
||||
|
||||
#mkdir $HOME/pzoo/scripts
|
||||
|
||||
#chown $USER:$USER $HOME/pzoo/scripts
|
||||
|
||||
#su - $USER -s /bin/bash -c "composer --working-dir=$HOME/scripts require guzzlehttp/guzzle:~6.0"
|
||||
|
||||
#pt=Path('/home/'+args.user+'/pzoo/tasks')
|
||||
|
||||
#pt.mkdir(mode=0o755, parents=True, exist_ok=True)
|
||||
|
||||
# Create scripts pzoo
|
||||
"""
|
||||
ps=Path('/home/'+args.user+'/pzoo/scripts')
|
||||
|
||||
ps.mkdir(mode=0o755, parents=True, exist_ok=True)
|
||||
|
||||
shutil.chown('/home/'+args.user+'/pzoo', args.user, args.user)
|
||||
|
||||
shutil.chown('/home/'+args.user+'/pzoo/scripts', args.user, args.user)
|
||||
|
||||
|
||||
if call("su - "+args.user+" -s /bin/bash -c \"composer --working-dir=/home/"+args.user+"/pzoo/scripts require guzzlehttp/guzzle:~6.0\"", shell=True)>0:
|
||||
print('Error, cannot install scripts for use in check scripts')
|
||||
exit(1)
|
||||
else:
|
||||
print('Composer dependencies for check scripts added successfully')
|
||||
|
||||
# Edit get_updates.py
|
||||
|
||||
with open('scripts/system/get_updates.py') as f:
|
||||
get_updates=f.read()
|
||||
|
||||
with open('/etc/cron.daily/get_updates.py', 'w') as f:
|
||||
url_updates=args.url.replace('/getinfo/', '/getupdates/')
|
||||
get_updates=get_updates.replace("http://url/to/server/token/ip", url_updates)
|
||||
f.write(get_updates)
|
||||
|
||||
os.chmod('/etc/cron.daily/get_updates.py', 0o700)
|
||||
"""
|
||||
if call("sudo pip3 install --upgrade git+https://bitbucket.org/paramecio/pastafaristats", shell=True)>0:
|
||||
print('Error, cannot install pastafari stats')
|
||||
exit(1)
|
||||
else:
|
||||
print('Added pastafari stats')
|
||||
|
||||
# Add configuration to pastafari stats
|
||||
|
||||
if not os.path.isdir('/etc/pastafari'):
|
||||
# Create pastafari dir
|
||||
p=Path('/etc/pastafari')
|
||||
p.mkdir(mode=0o755, parents=False, exist_ok=True)
|
||||
|
||||
with open('/etc/pastafari/stats.cfg', 'w') as f:
|
||||
|
||||
f.write("[DEFAULT]\n\nurl_server="+args.url_stats+"\ngroup="+args.group)
|
||||
|
||||
|
||||
with open('/etc/systemd/system/pastafaristats.service', 'w') as f:
|
||||
|
||||
systemd_unit="""
|
||||
# Save it in /etc/systemd/system/pastafaristats.service
|
||||
|
||||
[Unit]
|
||||
Description=Pastafari Stats
|
||||
After=syslog.target
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=pzoo
|
||||
Group=pzoo
|
||||
ExecStart=pastafaristats
|
||||
Restart=always
|
||||
Environment=PYTHONUNBUFFERED=1
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
"""
|
||||
|
||||
systemd_unit=systemd_unit.replace('pzoo', args.user)
|
||||
|
||||
f.write(systemd_unit)
|
||||
|
||||
if call("sudo systemctl enable pastafaristats.service && sudo systemctl start pastafaristats.service", shell=True)>0:
|
||||
print('Error, cannot start pastafari stats')
|
||||
exit(1)
|
||||
else:
|
||||
print('Pastafari stats ready')
|
||||
|
||||
print('{"error": 0, "status": 0, "progress": 100, "no_progress":0, "message": "Tools installed..."}')
|
||||
|
||||
sleep(1)
|
||||
|
||||
else:
|
||||
|
||||
print('Error installing the module, not valid url')
|
||||
|
||||
exit(1)
|
||||
1
scripts/system/sudoers.d/spanel
Normal file
1
scripts/system/sudoers.d/spanel
Normal file
|
|
@ -0,0 +1 @@
|
|||
spanel ALL=(ALL) NOPASSWD: ALL
|
||||
Loading…
Add table
Add a link
Reference in a new issue