Skip to content
Snippets Groups Projects
Commit 7b2b241a authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Use dirs for sections.

parent 5557dba6
No related branches found
No related tags found
No related merge requests found
Showing
with 133 additions and 21 deletions
#!/usr/bin/python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
......@@ -10,6 +10,10 @@ def setup(interactive=True):
'apt-get clean',
'apt-get update',
'apt-get install --yes make ipython ipython3 vim netcat git htop iotop bmon host lm-sensors pciutils ntp nfs-client smartmontools pwgen ntpdate dialog curl',
# Locale
'locale-gen en_GB.UTF-8',
'update-locale LANG=en_GB.UTF-8 LANGUAGE=en_GB.UTF-8 LC_ALL=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8',
# Vim colors
'[ -f ~/.vimrc ] || echo "color ron" > ~/.vimrc',
]
utils.run_commands(cmds)
......@@ -39,8 +43,8 @@ alias rmpyc='find . -name *.pyc -type f -delete && find . -name __pycache__ -typ
bashrc_path = os.path.expanduser('~/.bashrc')
bashrc = ''
if os.path.exists(bashrc_path):
with open(bashrc_path, 'r') as fd:
bashrc = fd.read()
with open(bashrc_path, 'r') as fo:
bashrc = fo.read()
new_bashrc = bashrc.replace('#force_color_prompt=yes', 'force_color_prompt=yes')
for line in lines.split('\n'):
line = line.strip()
......@@ -50,7 +54,7 @@ alias rmpyc='find . -name *.pyc -type f -delete && find . -name __pycache__ -typ
new_bashrc += '\n' + line
if new_bashrc != bashrc:
new_bashrc += '\n'
with open(bashrc_path, 'w') as fd:
fd.write(new_bashrc)
with open(bashrc_path, 'w') as fo:
fo.write(new_bashrc)
utils.log('bashrc file updated: %s' % bashrc_path)
utils.log('bashrc file up to date.')
#!/usr/bin/python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import subprocess
import utils
def setup(interactive=True):
# TODO: setup IP
dir_path = utils.get_dir(__file__)
cmds = [
# Locale
'locale-gen en_GB.UTF-8',
'update-locale LANG=en_GB.UTF-8 LANGUAGE=en_GB.UTF-8 LC_ALL=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8',
# NTP
'echo "Replacing /etc/ntp.conf"',
dict(line='write', template='%s/ntp.conf' % dir_path, target='/etc/ntp.conf', params=(
('{{ NTP_SERVER1 }}', utils.get_conf('NTP_SERVER1', 'ntp.ubuntu.com')),
)),
]
cmds = list()
# Create / update ubicast account
cmds.append('echo "Checking ubicast account"')
code, out = utils.exec_cmd(['id', 'ubicast'])
......@@ -45,3 +37,11 @@ def setup(interactive=True):
cmds.append('chown -R ubicast:ubicast /home/ubicast/.ssh')
utils.run_commands(cmds)
# Set ubicast password if any
pwd = utils.get_conf('SHELL_UBICAST_PWD')
if pwd and pwd != 'test':
p = subprocess.Popen(['passwd', '-q', 'ubicast'], stdin=subprocess.PIPE)
p.communicate(input=b'%(pwd)s\n%(pwd)s' % dict(pwd=pwd.encode('utf-8')))
if p.returncode != 0:
raise Exception('Failed to set ubicast account password.')
utils.log('\033[1;33m The ubicast account password has been set. \033[0m')
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import subprocess
import utils
def setup(interactive=True):
# Create / update admin account
utils.log('Checking admin account')
cmds = list()
code, out = utils.exec_cmd(['id', 'admin'])
if code != 0:
cmds.append('useradd -m -s /bin/bash admin')
out = ''
if 'sudo' not in out:
cmds.append('usermod -aG sudo admin')
cmds.append('mkdir -p /home/admin/.ssh')
cmds.append('chmod 700 /home/admin/.ssh')
cmds.append('chown -R admin:admin /home/admin/.ssh')
utils.run_commands(cmds)
# Set password if any
pwd = utils.get_conf('SHELL_ADMIN_PWD')
if pwd and pwd != 'test':
p = subprocess.Popen(['passwd', '-q', 'admin'], stdin=subprocess.PIPE)
p.communicate(input=b'%(pwd)s\n%(pwd)s' % dict(pwd=pwd.encode('utf-8')))
if p.returncode != 0:
raise Exception('Failed to set admin account password.')
utils.log('\033[1;33m The admin account password has been set. \033[0m')
#!/bin/bash
source /root/envsetup/conf.sh
KEY=~/.ssh/ubicast_support
VM_HYPER=$(grep VM_HYPER ${CONF} | awk -F "=" '{print$2}')
VM_STORE=$(grep VM_STORE ${CONF} | head -1 | awk -F "=" '{print$2}')
VM_STORE_LOCAL=$(grep VM_STORE_LOCAL ${CONF} | awk -F "=" '{print$2}')
if ( test -z $VM_NAME ); then
VM_NAME=$(cat ${CONF} | egrep ^ETC_HOSTNAME | head -1 | awk -F "=" '{print$2}')
else
VM_NAME=$(grep VM ${CONF} | awk -F "=" '{print$2}')
fi
ssh -i ${KEY} -o User=root ${VM_HYPER} "VBoxManage export ${VM_NAME} -o ${VM_STORE}/${VM_NAME}.ovf --ovf10"
# vbox conf file created
# generating vmware conf file
cp ${VM_STORE_LOCAL}/${VM_NAME}.ovf ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<vssd:VirtualSystemType>virtualbox-2.2</vssd:VirtualSystemType>@<vssd:VirtualSystemType>vmx-07</vssd:VirtualSystemType>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:Caption>sataController0</rasd:Caption>@<rasd:Caption>SCSIController</rasd:Caption>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:Description>SATA Controller</rasd:Description>@<rasd:Description>SCSIController</rasd:Description>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:ElementName>sataController0</rasd:ElementName>@<rasd:ElementName>SCSIController</rasd:ElementName>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:ResourceSubType>AHCI</rasd:ResourceSubType>@<rasd:ResourceSubType>lsilogic</rasd:ResourceSubType>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:ResourceType>20</rasd:ResourceType>@<rasd:ResourceType>6</rasd:ResourceType>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
# recherche n° ligne paragraphe à supp.
LIG=$(grep -n '<rasd:AddressOnParent>3</rasd:AddressOnParent>' ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf | awk -F ":" '{print$1}')
LIG0=$(( $LIG - 1 ))
LIG1=$(( $LIG0 + 9 ))
sed -i "${LIG0},${LIG1}d" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
# converting disk to qemu image
qemu-img convert -c -O qcow2 ${VM_STORE_LOCAL}/${VM_NAME}-disk1.vmdk ${VM_STORE_LOCAL}/${VM_NAME}.qcow2
echo -e "${CYAN}Files are available at ${VM_STORE_LOCAL}${NC}"
#!/bin/bash
source /root/envsetup/conf.sh
VM_STORE=/home/jallary/ubicast/TMP/ENVOI
VM_STORE_LOCAL=/home/jallary/ubicast/TMP/ENVOI
# depuis poste local
VBoxManage export ${VM_NAME} -o ${VM_STORE}/${VM_NAME}.ovf --ovf10
# generating vmware conf file
cp ${VM_STORE_LOCAL}/${VM_NAME}.ovf ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<vssd:VirtualSystemType>virtualbox-2.2</vssd:VirtualSystemType>@<vssd:VirtualSystemType>vmx-07</vssd:VirtualSystemType>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:Caption>sataController0</rasd:Caption>@<rasd:Caption>SCSIController</rasd:Caption>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:Description>SATA Controller</rasd:Description>@<rasd:Description>SCSIController</rasd:Description>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:ElementName>sataController0</rasd:ElementName>@<rasd:ElementName>SCSIController</rasd:ElementName>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:ResourceSubType>AHCI</rasd:ResourceSubType>@<rasd:ResourceSubType>lsilogic</rasd:ResourceSubType>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:ResourceType>20</rasd:ResourceType>@<rasd:ResourceType>6</rasd:ResourceType>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
# recherche n° ligne paragraphe à supp.
LIG=$(grep -n '<rasd:AddressOnParent>3</rasd:AddressOnParent>' ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf | awk -F ":" '{print$1}')
LIG0=$(( $LIG - 1 ))
LIG1=$(( $LIG0 + 9 ))
sed -i "${LIG0},${LIG1}d" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
# converting disk to qemu image
qemu-img convert -c -O qcow2 ${VM_STORE_LOCAL}/${VM_NAME}-disk1.vmdk ${VM_STORE_LOCAL}/${VM_NAME}.qcow2
echo -e "${CYAN}Files are available at ${VM_STORE_LOCAL}${NC}"
#!/usr/bin/python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import utils
......
File moved
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import utils
def setup(interactive=True):
dir_path = utils.get_dir(__file__)
cmds = [
# NTP
'echo "Replacing /etc/ntp.conf"',
dict(line='write', template='%s/ntp.conf' % dir_path, target='/etc/ntp.conf', params=(
('{{ NTP_SERVER1 }}', utils.get_conf('NTP_SERVER1') or 'ntp.ubuntu.com'),
)),
]
utils.run_commands(cmds)
File moved
#!/usr/bin/python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import utils
......
File moved
File moved
#!/usr/bin/python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
......
File moved
#!/usr/bin/python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import re
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment