138 lines
2.6 KiB
Bash
138 lines
2.6 KiB
Bash
#!/usr/bin/env sh
|
|
|
|
cd $(dirname "$0")
|
|
|
|
GREP='/usr/bin/env grep -E'
|
|
SCREEN='/usr/bin/env screen'
|
|
SED='/usr/bin/env sed -E'
|
|
if [ `uname -s` = "FreeBSD" ]; then
|
|
SU="/usr/bin/env su"
|
|
else
|
|
SU='/usr/bin/env su -s /bin/sh'
|
|
fi
|
|
PERL='/usr/bin/env perl'
|
|
|
|
# Install missing packages
|
|
DEB_PACKAGES_LIST="screen libxml-libxml-perl libgearman-client-perl"
|
|
ARCH_PACKAGES_LIST="screen"
|
|
GENTOO_PACKAGES_LIST="app-misc/screen dev-perl/XML-LibXML"
|
|
FBSD_PACKAGES_LIST="screen p5-XML-LibXML p5-Gearman p5-Term-ANSIColor"
|
|
|
|
KERNEL=`uname -s`
|
|
|
|
|
|
if [ "$KERNEL" = "FreeBSD" ]
|
|
then
|
|
|
|
for PK in `echo $FBSD_PACKAGES_LIST`
|
|
do
|
|
if ! pkg info "$PK" > /dev/null 2> /dev/null
|
|
then
|
|
if ! PACKAGESITE="http://canon.acu.epita.fr/repo-lab" pkg install "$PK"
|
|
then
|
|
echo "Error during installation of $PK"
|
|
exit 1
|
|
fi
|
|
fi
|
|
done
|
|
|
|
if ! getent passwd | grep "guantanamo:" > /dev/null 2> /dev/null
|
|
then
|
|
pw useradd guantanamo -u 941 -d /home/guantanamo -s /bin/false
|
|
fi
|
|
|
|
elif [ "$KERNEL" = "Linux" ]
|
|
then
|
|
|
|
if [ -f "/etc/debian_version" ]
|
|
then
|
|
|
|
if ! whereis dpkg > /dev/null 2> /dev/null
|
|
then
|
|
if ! aptitude install dpkg
|
|
then
|
|
echo "Error during installation of $PK"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
for PK in $DEB_PACKAGES_LIST
|
|
do
|
|
if ! dpkg -l | grep "^ii" | grep "$PK" > /dev/null 2> /dev/null
|
|
then
|
|
aptitude install "$PK"
|
|
fi
|
|
done
|
|
|
|
elif [ -f "/etc/arch-release" ]
|
|
then
|
|
|
|
for PK in $ARCH_PACKAGES_LIST
|
|
do
|
|
if ! pacman -Qi "$PK" > /dev/null 2> /dev/null
|
|
then
|
|
if ! pacman -S "$PK"
|
|
then
|
|
echo "Error during installation of $PK"
|
|
exit 1
|
|
fi
|
|
fi
|
|
done
|
|
|
|
elif [ -f "/etc/gentoo-release" ]
|
|
then
|
|
|
|
for PK in $GENTOO_PACKAGES_LIST
|
|
do
|
|
if ! equery list "$PK" > /dev/null 2> /dev/null
|
|
then
|
|
if ! emerge "$PK"
|
|
then
|
|
echo "Error during installation of $PK"
|
|
exit 1
|
|
fi
|
|
fi
|
|
done
|
|
|
|
else
|
|
|
|
echo "Unsupported GNU/Linux distribution :("
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
|
# Add guantanamo user if missing
|
|
if ! getent passwd | grep "guantanamo:" > /dev/null 2> /dev/null
|
|
then
|
|
useradd --shell /bin/false --uid 941 guantanamo &&
|
|
mkdir -p /home/guantanamo
|
|
fi
|
|
|
|
chown -R guantanamo:guantanamo /home/guantanamo
|
|
|
|
else
|
|
|
|
echo "Unsupported operating system :("
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
chown -R guantanamo .
|
|
|
|
if [ $# -gt 0 ]
|
|
then
|
|
ARCHNAME=$1
|
|
else
|
|
echo "Expected at first argument: node name. For example: hurd-ia64"
|
|
exit 1
|
|
fi
|
|
|
|
CMD="$SCREEN -S 'guantanamo_$ARCHNAME' -d -m sh -c 'while true; do perl guantanamo_node.pl $ARCHNAME; done'"
|
|
|
|
if [ "x$UID" = "x0" ]
|
|
then
|
|
echo "$CMD" | $SU guantanamo
|
|
else
|
|
$CMD
|
|
fi
|