1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-03-09 15:40:17 +00:00

initial checkin -- May 27, 2017

This commit is contained in:
George Hunt 2017-05-27 11:09:50 -07:00
commit 845632d0ac
488 changed files with 41559 additions and 0 deletions

106
scripts/ansible Executable file
View file

@ -0,0 +1,106 @@
#!/bin/bash -x
#TODO.md
yum_makecache_retry() {
tries=0
until [ $tries -ge 5 ]
do
yum makecache && break
let tries++
sleep 1
done
}
if [ "x$KITCHEN_LOG" = "xDEBUG" -o "x$OMNIBUS_ANSIBLE_LOG" = "xDEBUG" ]; then
export PS4='(${BASH_SOURCE}:${LINENO}): - [${SHLVL},${BASH_SUBSHELL},$?] $ '
set -x
fi
if [ ! $(which ansible-playbook) ]; then
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ] || [ -f /etc/system-release ] || grep -q 'Amazon Linux' /etc/system-release; then
# Install required Python libs and pip
# Fix EPEL Metalink SSL error
# - workaround: https://community.hpcloud.com/article/centos-63-instance-giving-cannot-retrieve-metalink-repository-epel-error
# - SSL secure solution: Update ca-certs!!
# - http://stackoverflow.com/q/26734777/645491#27667111
# - http://serverfault.com/q/637549/77156
# - http://unix.stackexchange.com/a/163368/7688
yum -y install ca-certificates nss
yum clean all
rm -rf /var/cache/yum
yum_makecache_retry
yum -y install epel-release
# One more time with EPEL to avoid failures
yum_makecache_retry
yum -y install python-pip PyYAML python-jinja2 python-httplib2 python-keyczar python-paramiko git
# If python-pip install failed and setuptools exists, try that
if [ -z "$(which pip)" -a -z "$(which easy_install)" ]; then
yum -y install python-setuptools
easy_install pip
elif [ -z "$(which pip)" -a -n "$(which easy_install)" ]; then
easy_install pip
fi
# Install passlib for encrypt
yum -y groupinstall "Development tools"
yum -y install python-devel MySQL-python sshpass && pip install pyrax pysphere boto passlib dnspython
# Install Ansible module dependencies
yum -y install bzip2 file findutils git gzip hg svn sudo tar which unzip xz zip libselinux-python
[ -n "$(yum search procps-ng)" ] && yum -y install procps-ng || yum -y install procps
elif [ -f /etc/debian_version ] || [ grep -qi ubuntu /etc/lsb-release ] || grep -qi ubuntu /etc/os-release; then
apt-get update
# Install via package
# apt-get update && \
# apt-get install --no-install-recommends -y software-properties-common && \
# apt-add-repository ppa:ansible/ansible && \
# apt-get update && \
# apt-get install -y ansible
# Install required Python libs and pip
apt-get install -y python-pip python-yaml python-jinja2 python-httplib2 python-paramiko python-pkg-resources
[ -n "$( apt-cache search python-keyczar )" ] && apt-get install -y python-keyczar
if ! apt-get install -y git ; then
apt-get install -y git-core
fi
# If python-pip install failed and setuptools exists, try that
if [ -z "$(which pip)" -a -z "$(which easy_install)" ]; then
apt-get -y install python-setuptools
easy_install pip
elif [ -z "$(which pip)" -a -n "$(which easy_install)" ]; then
easy_install pip
fi
# If python-keyczar apt package does not exist, use pip
[ -z "$( apt-cache search python-keyczar )" ] && sudo pip install python-keyczar
# Install passlib for encrypt
apt-get install -y build-essential
apt-get install -y python-all-dev python-mysqldb sshpass && pip install pyrax pysphere boto passlib dnspython
# Install Ansible module dependencies
apt-get install -y bzip2 file findutils git gzip mercurial procps subversion sudo tar debianutils unzip xz-utils zip python-selinux
else
echo 'WARN: Could not detect distro or distro unsupported'
echo 'WARN: Trying to install ansible via pip without some dependencies'
echo 'WARN: Not all functionality of ansible may be available'
fi
mkdir /etc/ansible/
echo -e '[local]\nlocalhost\n' > /etc/ansible/hosts
pip install ansible==2.2
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ] || [ -f /etc/system-release ] || grep -q 'Amazon Linux' /etc/system-release; then
# Fix for pycrypto pip / yum issue
# https://github.com/ansible/ansible/issues/276
if ansible --version 2>&1 | grep -q "AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'" ; then
echo 'WARN: Re-installing python-crypto package to workaround ansible/ansible#276'
echo 'WARN: https://github.com/ansible/ansible/issues/276'
pip uninstall -y pycrypto
yum erase -y python-crypto
yum install -y python-crypto python-paramiko
fi
fi
fi

19
scripts/debian-startup Executable file
View file

@ -0,0 +1,19 @@
#!/bin/bash -x
# required to start loading XSCE
set -e
apt-get update
apt-get upgrade
apt-get install -y mlocate vim emacs
cd /opt
mkdir schoolserver
cd schoolserver
git clone https://github.com/xsce/xsce --depth 1
cd xsce
# install ansible using script
./scripts/ansible
./runansible

283
scripts/prep-storage.sh.wip Normal file
View file

@ -0,0 +1,283 @@
#!/bin/bash
EXTMEDIA=`ls -la /mnt/*`
MMC0=`ls /dev | grep mmcblk0 | wc | awk '{print $1}'`
MMC1=`ls /dev | grep mmcblk1 | wc | awk '{print $1}'`
USB=`ls /dev | grep sd | wc | awk '{print $1}'`
function warn()
{
echo "######################################################"
echo ""
echo ""
echo "WARNING external SD-card or hard-disk NOT detected"
echo "Please insert SD-card or connect your external hard"
echo "disk before running bootsrap-xo"
echo ""
echo ""
echo "#####################################################"
echo ""
read -p "Press [Enter] key to shutdown"
echo ""
echo ""
echo "shutting down in 5 seconds"
sleep 5
shutdown now
exit 1
}
function unsupported()
{
echo "#####################################################"
echo ""
echo ""
echo "WARNING detected external media partition layout is"
echo "unsuppoted. Please try a different SD-card or usbkey"
echo ""
echo ""
echo "#####################################################"
echo ""
read -p "Press [Enter] key to shutdown"
echo ""
echo ""
echo "shutting down in 5 seconds"
sleep 5
shutdown now
exit 1
}
function library_1st()
{
echo "#####################################################"
echo ""
echo ""
echo "WARNING detected 2 USB storage units. In order to"
echo "protect the data on the one that will not become a"
echo "permanent part of the XS server, please ensure the"
echo "premanent drive is inserted in a slot when turning."
echo "on your XO. Please insert the usb drive containing"
echo "the XSCE installaton media before typing 'bootstrap-xo'"
echo ""
echo ""
echo "#####################################################"
echo ""
echo ""
read -p "Press [Enter] key to shutdown"
echo ""
echo ""
echo "shutting down in 5 seconds"
sleep 5
shutdown now
exit 1
}
function get_devices()
{
FOUNDDEVS=
BLKID=`blkid | awk '{split($0,a,":"); print a[1]}'`
for blk in $BLKID; do
FOUNDDEVS="$FOUNDDEVS $blk"
done
}
function get_root_device()
{
ROOTDEV=
BLKID=`blkid | awk '{split($0,a,":"); print a[1]}'`
for blk in $BLKID; do
ROOTDEV=`echo $blk | grep root`
done
}
function find_repo()
{
MNT=`mount | grep dev/sdb | awk '{print $3}'`
if ! [ -d $MNT/xs-repo ]; then
library_1st
fi
}
function togglepart()
{
cat <<EOF | fdisk /dev/mmcblk0
t
83
w
EOF
partprobe $MEDIADEV
mkfs.ext4 -L library $MEDIADEV
MEDIADEV2=$MEDIADEV
MEDIAMNT=/library
}
function togglepart-usb()
{
cat <<EOF | fdisk /dev/sda
t
83
w
EOF
partprobe $MEDIADEV2
mkfs.ext4 -L library $MEDIADEV2
MEDIAMNT=/mnt/usb0
}
function partition_usb_hd()
{
cat <<EOF | fdisk /dev/sda
n
t
83
w
EOF
partprobe $MEDIADEV2
mkfs.ext4 -L library $MEDIADEV2
MEDIAMNT=/mnt/usb0
}
function find_repo2()
{
echo "findrepo2"
maybe=""
for parts in `ls -la /dev/sd*1`; do
maybe=`findmnt -n -o TARGET -S $parts`
echo "maybe is $maybe"
if ! [ -d $maybe/xs-repo ]; then
MEDIADEV2="/dev/$parts"
break
fi
done
}
##### routine starts here #####
get_devices
DEVS=`echo $FOUNDDEVS | wc | awk '{print $1}'`
echo "found block devices $FOUNDDEVS"
echo "found $MMC0 character devices for mmcblk0"
echo "found $MMC1 character devices for mmcblk1"
if [ $MMC0 = 5 ]; then
if [ $MMC1 = 1 ]; then
unsupported
elif ! [ -b /dev/mmcblk1p1 ]; then
unsupported
fi
if ! [ -n $MMC0 ]; then
MEDIADEV=/dev/mmcblk1p1
fi
fi
if [ $MMC1 = 5 ]; then
if [ $MMC0 = 1 ]; then
unsupported
elif ! [ -b /dev/mmcblk0p1 ]; then
unsupported
fi
if ! [ -n $MMC1 ]; then
MEDIADEV=/dev/mmcblk0p1
fi
fi
MEDIASTRING=`blkid | grep $MEDIADEV`
echo "found $MEDIASTRING"
for i in $MEDIASTRING; do
test=`echo $i | awk '{split($0,a,"="); print a[1]}'`
test2=`echo $i | awk '{split($0,a,"="); print a[2]}' | sed -e 's/"//' | sed -e 's/"//'`
echo "test $test"
echo "test2 $test2"
case $test in
"UUID")
echo "$MEDIADEV is $i"
;;
"TYPE")
if [ $test2 = "vfat" ]; then
MNT=`mount | grep $MEDIADEV | awk '{print $3}'`
echo "unmounting $MNT"
if [ x$MNT != x ]; then
umount $MNT
fi
echo "calling togglepart"
togglepart
break
else
ext_ver=`echo $test2 | grep ext`
echo "test ext_mmc $test2 $ext_ver"
if ! [ -z $ext_ver ];then
echo "found ext2|3|4 filesystem on external SD-card"
MEDIAMNT=/library
MEDIADEV2=$MEDIADEV
break
else
echo "ext2|3|4 not found"
fi
fi
;;
esac
done
echo "usb is $USB "
if [ $USB = 0 ];then
echo "no external usb media found"
elif [ $USB -g 2 ]; then
find_repo2
else
MEDIAMNT=/mnt/usb0
MEDIADEV2=/dev/sda1
fi
if [ -z $MEDIADEV2 ];then
echo "DONE - nothing to do"
warn
else
echo "media dev is: $MEDIADEV2"
fi
if ! [ -c $MEDIADEV2 ];then
# TODO check parts on parent
# then call partition_usb_hd
warn
fi
echo "cleaning fstab"
sed -i '/swap/d' /etc/fstab
sed -i '/usb0/d' /etc/fstab
sed -i '/library/d' /etc/fstab
if [ -d /library ]; then
echo "saving old /library as /library.save"
mv /library /library.save
fi
label=`e2label $MEDIADEV2`
if [ -z $label ];then
e2label $MEDIADEV2 library
fi
if [ $MEDIADEV2 = /dev/sda1 ];then
ln -s /mnt/usb0 /library
else
mkdir /library
fi
uuid=`blkid -s UUID $MEDIADEV2 | gawk '{print $2}'`
echo UUID is $uuid
echo "populating fstab for $MEDIADEV2 using $uuid"
echo "$uuid $MEDIAMNT auto defaults,noatime 0 0" >> /etc/fstab
echo "mounting $uuid at $MEDIAMNT"
mount -a
if ! [ -d $MEDIAMNT/swap ]; then
mkdir $MEDIAMNT/swap
fi
echo "creating swap.img"
dd if=/dev/zero of=$MEDIAMNT/swap/swap.img bs=1024 count=10480
mkswap $MEDIAMNT/swap/swap.img
chown root:root $MEDIAMNT/swap/swap.img
echo "$MEDIAMNT/swap/swap.img swap swap defaults 0 0" >> /etc/fstab
swapon $MEDIAMNT/swap/swap.img
exit 0

74
scripts/refresh-wiki-docs.sh Executable file
View file

@ -0,0 +1,74 @@
#!/bin/bash -x
# pull down repo wiki, and imbed in docs subdirectory
source /etc/xsce/xsce.env
REPONAME=xsce
REPO=https://github.com/XSCE
WIKI=xsce-wiki
TARGET_URL=/info
WWWROOT=/library/www/html
INPUT=/tmp/${WIKI}
OUTPUT=/tmp/${WIKI}.out
# this script is located in the scritps/ directory in the local repo
SCRIPTDIR=$(dirname $0)
pushd $SCRIPTDIR
rm -rf $INPUT
rm -rf $OUTPUT
mkdir -p $INPUT
mkdir -p $OUTPUT
git clone $REPO/$REPONAME.wiki.git $INPUT
# convert the markdown docs to html
which pandoc
if [ $? -ne 0 ]; then
if [ "$OS" = "CentOS" ] || [ "$OS" = "Fedora" ]; then
yum install -y pandoc
else
apt-get install -y pandoc
fi
fi
mkdir -p $WWWROOT$TARGET_URL/html
# To Do find more links to rewrite, especially after moving from xsce to iiab
for f in `ls /tmp/${WIKI}`; do
FTRIMMED=${f%.md}
if [ $FTRIMMED = "Home" ]; then FTRIMMED=index;fi
pandoc -s /tmp/${WIKI}/$f -o $OUTPUT/$FTRIMMED.html
# make links refer to local directory
sed -i -e "s|$REPO/$REPONAME/wiki/\(.*\)\">|./\1.html\">|" $OUTPUT/$FTRIMMED.html
sed -i -e "s|http://schoolserver.org/faq|/info/html/FAQ|" $OUTPUT/$FTRIMMED.html
sed -i -e "s|$REPO/$REPONAME/blob/release-.*/\(.*\)\">|./\1.html\">|" $OUTPUT/$FTRIMMED.html
done
rsync -av $OUTPUT/ $WWWROOT$TARGET_URL
# copy the faq and other things
lynx -reload -source http://wiki.laptop.org/go/XS_Community_Edition/FAQ > $WWWROOT$TARGET_URL/html/FAQ
lynx -reload -source http://wiki.laptop.org/go/XS_Community_Edition/Security > $WWWROOT$TARGET_URL/html/Security
lynx -reload -source http://wiki.laptop.org/go/XS_Community_Edition/local_vars.yml > $WWWROOT$TARGET_URL/html/local_vars.yml
# fetch the embedded help pages from the admin console
#for f in `ls ../roles/xsce-admin/files/console/help`; do
# FTRIMMED=${f%.rst}
# pandoc -s ../roles/xsce-admin/files/console/help/$f -o ../docs/html/offline-help/$FTRIMMED.html
# # make links refer to local directory
# sed -i -e "s|$REPO/$REPONAME/wiki/\(.*\)\">|./\1.html\">)|" ../docs/html/$FTRIMMED.html
#done
# fetch the recent release notes
for f in `ls ../Release*`; do
# FTRIMMED=${f%.md}
FTRIMMED=${f:2}
pandoc -s $f -o $WWWROOT$TARGET_URL$FTRIMMED.html
# make links refer to local directory
sed -i -e "s|$REPO/$REPONAME/wiki/\(.*\)\">|./\1.html\">)|" $WWWROOT$TARGET_URL$FTRIMMED.html
done
rm -rf $INPUT
rm -rf $OUTPUT
popd