To create new wiki account, please join us on #znc at Libera.Chat and ask admins to create a wiki account for you. You can say thanks to spambots for this inconvenience.

Chroot/Script

From ZNC
Revision as of 11:01, 17 December 2011 by DarthGandalf (talk | contribs) (Created page with "{{ambox|type=serious|text= Running ZNC in a chrooted environment is unsupported. Either you know what you are doing, or you don't do it! }} This script will download the lates...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
This message box is using an invalid "type=serious" parameter and needs fixing.

[[Category:Wikipedia message box parameter needs fixing|Template:Main otherChroot/Script]]

This script will download the latest ZNC snapshot and install it so that it can be used for running a chrooted ZNC. Read the comments in the beginning of the script to learn more.

#!/bin/bash

# The source .tar.gz that is installed for chrooting
SOURCE="http://znc.in/nightly/znc-svn-latest.tar.gz"
# The chroot used
CHROOT="/var/chroot/znc"
# The user for running ZNC
USER="znc"
# Arguments to configure (like --disable-shit etc)
CONFIGURE_ARGS=""
# Arguments to make
MAKE_ARGS="-j3"

# Don't change stuff after here

if [[ $UID == 0 ]]
then
  echo "You don't need to (and shouldn't) run this file as root!"
  exit
fi

DL="dl-znc.tar.gz"
TMPDIR=$(mktemp -d)
# Automatically clean up
trap 'rm -rf $TMPDIR' EXIT INT HUP QUIT TERM

cd $TMPDIR

log()
{
  echo
  tput smso
  echo $@
  tput rmso
}

log Downloading...
wget -O $TMPDIR/$DL $SOURCE || exit

log Extracting...
tar -xzf $DL || exit

# We assume this extracts to znc*
cd znc* || exit

log Configuring...
./configure $CONFIGURE_ARGS --prefix=/usr || exit

log Compiling...
make $MAKE_ARGS || exit

log Installing to ${CHROOT}...
make install DESTDIR=${CHROOT} || exit

mkdir -p $CHROOT/etc
mkdir -p $CHROOT/lib
mkdir -p $CHROOT/usr/lib
mkdir -p $CHROOT/dev
mkdir -p $CHROOT/home
mkdir -p $CHROOT/home/$USER

log "Copying needed libs... (All are saved in ${CHROOT}/usr/lib)"
cd $CHROOT
ldd $CHROOT/usr/bin/znc |
  sed -e 's/[ \t]*//g' -e 's/^.*=>//' -e 's/(.*)$//' |
  while read file
  do
    if [[ $file == '' ]]
    then
      continue
    fi

    if [[ -f $CHROOT/$file ]]
    then
      rm $CHROOT/$file
    fi

    echo "Copying ${file}..."
    dir=$(echo $file | sed 's:/[^/]*$::')
    f=$(echo $file | sed 's:^.*/::')
    mkdir -p ${CHROOT}/$dir
    cp -p $file $CHROOT/lib/$f
  done

log "Symlinking /usr/lib64 to /usr/lib... (just in case ;)"
ln -s lib $CHROOT/usr/lib64

log Trying to copy files needed for DNS...
cp -p /etc/hosts  $CHROOT/etc/
cp -p /etc/resolv.conf  $CHROOT/etc/
cp -p /lib/libnss_dns.so.2 $CHROOT/lib \
  || log Copying libnss_dns.so.2 failed, DNS may be broken!
cp -p /lib/libresolv.so.2 $CHROOT/lib \
  || log Copying libresolv.so.2 failed, DNS may be broken!

cat <<OUT

Done

You should now su to root.

There are some files in the chroot which need to be created by root:
(This assumes you are using linux, good luck for other OS)
    mknod -m 644 ${CHROOT}/dev/random c 1 8
    mknod -m 644 ${CHROOT}/dev/urandom c 1 9
    mknod -m 666 ${CHROOT}/dev/null c 1 3

You need a user and a group which will be used to run ZNC:
    useradd --user-group --home-dir=/home/$USER $USER
    chown -R $USER:$USER ${CHROOT}

After this, you should be able to start ZNC.

To start up ZNC for creating a configuration, run this:
    su $USER -- -c '${CHROOT}/usr/bin/znc --makeconf --datadir ${CHROOT}/home/$USER/.znc'

To start and stop use these commands:
    start-stop-daemon --chroot ${CHROOT} --chuid $USER:$USER --start --exec /usr/bin/znc
    start-stop-daemon --chroot ${CHROOT} --chuid $USER:$USER --stop --exec /usr/bin/znc
OUT