# HG changeset patch # User Eric Joseph-Alexandre # Date 1320135829 -3600 # Node ID 2d20f72ffb19cb1aa4569471679398fb9d577988 # Parent d7f371bbe726271dd83890eecb3bd9027fbb0a7f Add stuff for templates diff -r d7f371bbe726 -r 2d20f72ffb19 base-scripts/Makefile.vz --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base-scripts/Makefile.vz Tue Nov 01 09:23:49 2011 +0100 @@ -0,0 +1,45 @@ +# Build Slitaz template for OpenVZ +# +# 2011/01 Eric Joseph-Alexandre - +# Publish under GNU General Public License. + +MIRROR+=http://mirror.slitaz.org/iso/ +VERSION+=3.0 +FLAVOR+=base +SRC+=./777 +TMP+=/tmp + +all: + + +template: prepare tar-gz + +prepare: + @rm -rf $(SRC)/lib/modules + + # Set mtab config + rm -f $(SRC)/etc/mtab + ln -s /proc/mounts $(SRC)/etc/mtab + + # Set fstab config + echo '# /etc/fstab: in VE file system.' > $(SRC)/etc/fstab + echo '#' >> $(SRC)/etc/fstab + echo 'proc /proc proc defaults 0 0' >> $(SRC)/etc/fstab + echo 'devpts /dev/pts devpts defaults 0 0' >> $(SRC)/etc/fstab + + # Disable root login + sed -i '/^root.*/root:!:13525:0:99999:7:::/' $(SRC)/etc/shadow + + # Disable tty + sed -i 's/^tty/#tty/' $(SRC)/etc/shadow + + +tar-gz: + cd $(SRC) ; tar cvzf $(TMP)/slitaz-$(FLAVOR)-$(VERSION).tar.gz . + +download: + cd $(SRC) + + + +.PHONY: prepare template download diff -r d7f371bbe726 -r 2d20f72ffb19 base-scripts/kernel_migrate.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base-scripts/kernel_migrate.sh Tue Nov 01 09:23:49 2011 +0100 @@ -0,0 +1,36 @@ +#!/bin/sh +# + +KVER=2.6.32 +PREFIX=ovzkernel- +SUFFIX= +EXTRAVERSION=-i686 + + +for i in linux-* +do + if [ ! -d ${PREFIX}$(echo ${i##linux-})${SUFFIX} ]; then + cp -pa $i ${PREFIX}$(echo ${i##linux-})${SUFFIX} + sed -i -e "s/PACKAGE=.*/PACKAGE=\"${PREFIX}$(echo ${i##linux-})\"/" \ + -e "s/VERSION=.*/VERSION=\"${KVER}\"/" \ + -e "s/DEPENDS.*/DEPENDS=\"${PREFIX%%-}\"/" \ + -e "s/WANTED=.*/WANTED=\"${PREFIX%%-}\"/" \ + -e "s/\(WEB_SITE.*\)/\1\nEXTRAVERSION=\"${EXTRAVERSION}\"/" \ + -e "s/\(EXTRA.*\)/\1\nSOURCE=\"linux\"/" \ + -e "s!\(local path\)!\1\n\tsrc=\$WOK/\$WANTED/\$SOURCE-\$VERSION\n\t_pkg=\$WOK/\$WANTED/\$SOURCE-\$VERSION/_pkg\n\tKERNELRELEASE=\$( cat \$src/include/config/kernel.release 2> /dev/null)!" \ + -e "s!slitaz/list_modules.sh!\OpenVZ/list_modules.sh \${KERNELRELEASE}!" \ + -e "s/\$VERSION-slitaz/\${KERNELRELEASE}/" \ + -e "s/depmod -a \$VERSION-slitaz/depmod -a \${KERNELRELEASE}/" \ + ${PREFIX}$(echo ${i##linux-})${SUFFIX}/receipt + + sed -i '/chroot/ { + i\KERNELRELEASE=$(cat $1\/etc\/ovzkernel\/kernel\.release) + }' ${PREFIX}$(echo ${i##linux-})${SUFFIX}/receipt + + sed -i '/\tdepmod/ { + i\ + \ KERNELRELEASE=$(cat $1\/etc\/ovzkernel\/kernel\.release) + }' ${PREFIX}$(echo ${i##linux-})${SUFFIX}/receipt + fi +done + diff -r d7f371bbe726 -r 2d20f72ffb19 base-scripts/local.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base-scripts/local.sh Tue Nov 01 09:23:49 2011 +0100 @@ -0,0 +1,56 @@ +#!/bin/sh +# /etc/init.d/local.sh - Local startup commands. +# +# All commands here will be executed at boot time. +# +. /etc/init.d/rc.functions + +#~ (°- { Documentation dans /usr/share/doc. Utiliser 'less -EM' pour, +#~ //\ lire des fichiers, devenir root avec 'su' et éditer avec 'nano'. +#~ v_/_ Taper 'startx' pour lancer une session X. } + + +echo "Starting local startup commands... " + +echo "SliTaz GNU/Linux (`cat /etc/slitaz-release`)" > /etc/motd +echo >> /etc/motd +echo "(°- { Documentation dans /usr/share/doc. Utiliser 'less -EM' pour," >> /etc/motd +echo "//\ lire des fichiers, devenir root avec 'su' et éditer avec 'nano'." >> /etc/motd +echo "v_/_ Acces au panel : http://:3000 }" >> /etc/motd +echo >> /etc/motd +echo "Kernel : `uname -r`" >> /etc/motd +echo "hostname : `hostname`" >> /etc/motd +echo "ip : $(ifconfig br0 | grep inet | \ + cut -d ':' -f2 | cut -d ' ' -f1)" >> /etc/motd +echo >> /etc/motd + +echo "SliTaz GNU/Linux $(cat /etc/slitaz-release) ($(ifconfig br0 | grep inet | \ + cut -d ':' -f2 | cut -d ' ' -f1))" > /etc/issue +echo >> /etc/issue + +echo " * Settings Kernel parameters" +/sbin/sysctl -w -p /etc/sysctl.conf > /dev/null 2>&1 + +# Setting up owp and VZ in Live mode +if [ ! -f /var/lib/slitaz-vz ]; then + # vzquota doesn't work in live mode ( http://labs.slitaz.org/issues/380 ) + sed -i s/DISK_QUOTA=yes/DISK_QUOTA=no/ /etc/vz/vz.conf + + /usr/bin/ruby /usr/share/ovz-web-panel/utils/hw-daemon/hw-daemon.rb stop > /dev/null 2>&1 + + echo " * Settings hw-daemon" + echo "address = 127.0.0.1" > /usr/share/ovz-web-panel/utils/hw-daemon/hw-daemon.ini + echo "port = 7767" >> /usr/share/ovz-web-panel/utils/hw-daemon/hw-daemon.ini + + export RAND_KEY=`head -c 200 /dev/urandom | md5sum | awk '{ print \$1 }'` + echo "key = $RAND_KEY" >> /usr/share/ovz-web-panel/utils/hw-daemon/hw-daemon.ini + + # Add localhost in server list + echo " * Adding localhost to the list of controlled servers..." + #/usr/bin/ruby /usr/share/ovz-web-panel/script/runner -e production "HardwareServer.new(:host => 'localhost', :auth_key => '"$(echo $RAND_KEY)"').co + sqlite3 /usr/share/ovz-web-panel/db/production.sqlite3 "insert into hardware_servers(host,auth_key) values('localhost','"$(echo $RAND_KEY)"')" + /usr/bin/ruby /usr/share/ovz-web-panel/utils/hw-daemon/hw-daemon.rb start + + # Create slitaz-vz will prevent this configs. + date > /var/lib/slitaz-vz +fi diff -r d7f371bbe726 -r 2d20f72ffb19 base-scripts/network.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base-scripts/network.sh Tue Nov 01 09:23:49 2011 +0100 @@ -0,0 +1,226 @@ +#!/bin/sh +# /etc/init.d/network.sh - Network initialization boot script. +# Config file is: /etc/network.conf +# +. /etc/init.d/rc.functions + +if [ -z "$2" ]; then + . /etc/network.conf +else + . $2 +fi + + +Boot() { + # Set hostname. + echo -n "Setting hostname..." + /bin/hostname -F /etc/hostname + status + + # Configure loopback interface. + echo -n "Configuring loopback..." + /sbin/ifconfig lo 127.0.0.1 up + /sbin/route add 127.0.0.1 lo + status +} + + +eth() { +# Use ethernet + ifconfig $INTERFACE up +} + +wifi() { + # For wifi. Users just have to enable it through yes and usually + # essid any will work and the interface is autodetected. + if [ "$WIFI" = "yes" ] || grep -q "wifi" /proc/cmdline; then + ifconfig $INTERFACE down + + # Confirm if $WIFI_INTERFACE is the wifi interface + if [ ! -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then + echo "$WIFI_INTERFACE is not a wifi interface, changing it." + WIFI_INTERFACE=$(grep : /proc/net/dev | cut -d: -f1 | \ + while read dev; do iwconfig $dev 2>&1 | \ + grep -iq "essid" && { echo $dev ; break; }; \ + done) + [ -n "$WIFI_INTERFACE" ] && sed -i "s/^WIFI_INTERFACE=.*/WIFI_INTERFACE=\"$WIFI_INTERFACE\"/" /etc/network.conf + fi + + echo -n "Configuring $WIFI_INTERFACE..." + ifconfig $WIFI_INTERFACE up + if iwconfig $WIFI_INTERFACE | grep -q "Tx-Power"; then + iwconfig $WIFI_INTERFACE txpower on + fi + status + + [ -n "$WPA_DRIVER" ] || WPA_DRIVER="wext" + + + IWCONFIG_ARGS="" + [ -n "$WIFI_MODE" ] && IWCONFIG_ARGS="$IWCONFIG_ARGS mode $WIFI_MODE" + [ -n "$WIFI_CHANNEL" ] && IWCONFIG_ARGS="$IWCONFIG_ARGS channel $WIFI_CHANNEL" + # unencrypted network + if [ "$WIFI_KEY" == "" -o "$WIFI_KEY_TYPE" == "none" ]; +then + iwconfig $WIFI_INTERFACE essid "$WIFI_ESSID" $IWCONFIG_ARGS + fi + # encrypted network + [ -n "$WIFI_KEY" ] && case "$WIFI_KEY_TYPE" in + wep|WEP) + IWCONFIG_ARGS="$IWCONFIG_ARGS key $WIFI_KEY" + iwconfig $WIFI_INTERFACE essid "$WIFI_ESSID" $IWCONFIG_ARGS +# wpa_supplicant can also deal with wep encryption but iwconfig is preferred +# Tip: Use unquoted strings for hexadecimal key in wep_key0 +# cat /etc/wpa_supplicant.conf > /tmp/wpa.conf +# cat >> /tmp/wpa.conf < /tmp/wpa.conf # load pre-configured multiple profiles + cat >> /tmp/wpa.conf < /tmp/wpa.conf + cat >> /tmp/wpa.conf <> /etc/resolv.conf + done + else + touch /etc/resolv.conf + fi + fi +} + +# Stopping everything +Stop() { + echo "Stopping all interfaces" + ifconfig $INTERFACE down + ifconfig $WIFI_INTERFACE down + + echo "Killing all daemons" + killall udhcpc + killall wpa_supplicant 2>/dev/null + + if iwconfig $WIFI_INTERFACE | grep -q "Tx-Power"; then + echo "Shutting down wifi card" + iwconfig $WIFI_INTERFACE txpower off + fi +} + +Start() { + eth + wifi + dhcp + static_ip + # change default lxpanel panel iface + sed -i "s/iface=.*/iface=$INTERFACE/" /etc/lxpanel/default/panels/panel +} + + +# looking for arguments: +if [ -z "$1" ]; then + Boot + Start +else + case $1 in + start) + Start ;; + stop) + Stop ;; + restart) + Stop + Start ;; + *) + echo "" + echo -e "\033[1mUsage:\033[0m /etc/init.d/`basename $0` [start|stop|restart]" + echo "" + echo -e " Default configuration file is \033[1m/etc/network.conf\033[0m" + echo -e " You can specify another configuration file in the second argument:" + echo -e " \033[1mUsage:\033[0m /etc/init.d/`basename $0` [start|stop|restart] file.conf" + echo "" + + esac +fi diff -r d7f371bbe726 -r 2d20f72ffb19 base-scripts/rc.network --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base-scripts/rc.network Tue Nov 01 09:23:49 2011 +0100 @@ -0,0 +1,79 @@ +#!/bin/sh +# rc.network, set network config stuff for OpenVZ container. +# +# + +. /etc/init.d/rc.functions + +if [ -z "$2" ]; then + . /etc/network.conf +else + . $2 +fi + +Boot() { + # Set hostname. + /bin/hostname -F /etc/hostname + + # We are always start loopback + ifconfig lo up +} + +_ifconfig() { + # Use ethernet + ifconfig $INTERFACE up + + # Start all network devices + for interface in /etc/network/ifconfig-* + do + DEVICE=$(echo "`basename $interface`" | sed 's/ifconfig-//') + . $interface + if [ "$ONBOOT" = "yes" ]; then + case $MODE in + static) + /sbin/ifconfig $DEVICE $IP netmask $NETMASK broadcast $BROADCAST up ;; + dhcp) + /sbin/udhcpc -b -T 1 -A 12 -i $INTERFACE -p /var/run/udhcpc.$INTERFACE.pid ;; + *) + echo "$MODE is not supported." ;; + esac + fi + done +} + +# Stopping everything +Stop() { + echo "Stopping all interfaces" + ifconfig $INTERFACE down + + # Stopping all network interfaces. + for interface in /etc/network/ifconfig-* + do + DEVICE=$(echo "`basename $interface`" | sed 's/ifconfig-//') + . $interface + if [ "$ONBOOT" = "yes" ]; then + /sbin/ifconfig $DEVICE down + fi + done + +} + +Start() { + _ifconfig +} + +# looking for arguments: +case $1 in + start) + Start ;; + stop) + Stop ;; + restart) + Stop + Start + ;; + *) + Boot + Start + ;; +esac diff -r d7f371bbe726 -r 2d20f72ffb19 base-scripts/rcS --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base-scripts/rcS Tue Nov 01 09:23:49 2011 +0100 @@ -0,0 +1,255 @@ +#!/bin/sh +# /etc/init.d/rcS - Initial boot script for SliTaz GNU/Linux. +# Config file is : /etc/rcS.conf +# +# rcS is the main initialization script used to check fs, mount, clean, +# run scripts and start daemons. +# +. /etc/init.d/rc.functions +. /etc/rcS.conf + +# Boot time. +bootdate=`date +%s` + +if [ "$1" != "logged" ]; then # logged + +echo "Processing /etc/init.d/rcS..." + +# Mount /proc. +echo -n "Mounting proc filesystem..." +/bin/mount proc +status + +# Parse cmdline args for earlier boot options. All other boot options +# are in /etc/init./bootopts.sh. +echo -n "Searching for early boot options..." +for opt in `cat /proc/cmdline` +do + case $opt in + fastbootx|fbx) + export FAST_BOOT_X="yes" ;; + cdrom=*) + export CDROM=${opt#cdrom=} ;; + modprobe=*) + export MODPROBE="yes" ;; + config=*) + export CONFIG=${opt#config=} ;; + *) + continue ;; + esac +done +status + +# Start Udev to populate /dev and handle hotplug events +if [ "$UDEV" = "yes" ]; then + echo -n "Starting udev daemon..." + /sbin/udevd --daemon + status + echo -n "Udevadm requesting events from the Kernel..." + udevadm trigger + status + echo -n "Udevadm waiting for the event queue to finish..." + udevadm settle + status + echo "/sbin/udevd" > /proc/sys/kernel/hotplug +fi + +# Before mounting filesystems we check fs specified in the file +# /etc/rcS.conf and variable $CHECK_FS. +if [ -n "$CHECK_FS" ]; then + mount -o remount,ro / + for i in $CHECK_FS + do + echo "Checking filesystem on : $i" + /sbin/e2fsck -p $i + done +fi + +# Remount rootfs rw. +echo "Remounting rootfs read/write..." +/bin/mount -o remount,rw / + +# Mount filesystems in /etc/fstab. +echo "Mounting filesystems in fstab..." +/bin/mount -a + +# Store boot messages to log files. +/bin/dmesg > /var/log/dmesg.log & +vcsa2txt < /dev/vcsa1 | awk 'BEGIN {s=0} /^Processing|^.witching/ {s=1} { if (s) print }' >/var/log/boot.log +script -a -q -c '/etc/init.d/rcS logged' /var/log/boot.log + +else # logged + +# Clean up the system. +if [ "$CLEAN_UP_SYSTEM" = "yes" ]; then + echo -n "Cleaning up the system..." + find /var/run -name "*.pid" -type f | xargs /bin/rm -f + /bin/rm -rf /tmp /var/run/dbus/* /var/run/hald/pid /var/lock/* + /bin/mkdir -p /tmp && /bin/chmod 1777 /tmp + status +else + echo "System clean up is disabled in /etc/rcS.conf..." + echo -n "Keeping all tmp and pid files..." + status +fi + +# Set up tmp X11 and ICE dir. +#~ echo -n "Setting up tmp X11 and ICE unix dir..." +#~ /bin/mkdir -p /tmp/.X11-unix /tmp/.ICE-unix +#~ /bin/chmod 1777 /tmp/.X11-unix /tmp/.ICE-unix +#~ status + +# Fast boot into X for HD install or custom Live system. We need +# keymap settings since Xvesa dumps the console mapping and a correct +# slim configuration for screen resolution. DBUS and HAL must also start +# before X session (manual login or autologin) to have devices in PCmanFM. +if [ "$FAST_BOOT_X" = "yes" ]; then + /etc/init.d/i18n.sh + /etc/init.d/dbus start + /etc/init.d/hald start + /etc/init.d/slim start & +fi + +# Create /dev/cdrom if needed (symlink does not exist on LiveCD). +# Also add /dev/cdrom to fstab if entry does not exist. +if [ -n "$CDROM" ]; then + DRIVE_NAME=${CDROM#/dev/} +else + DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3` +fi +if [ -n "$DRIVE_NAME" -a ! "`readlink /dev/cdrom`" ]; then + echo -n "Creating symlink : /dev/cdrom..." + ln -s /dev/$DRIVE_NAME /dev/cdrom + ln -s /dev/$DRIVE_NAME /dev/dvd + status +fi +if ! grep -q "/dev/cdrom" /etc/fstab; then + echo -n "Adding /dev/cdrom to fstab..." + echo '/dev/cdrom /media/cdrom iso9660 user,ro,noauto 0 0' \ + >> /etc/fstab + status +fi +# Chmod hack on each boot for Asunder and burnbox. Allowing all users +# to burn/rip CD/DVD. +if [ -n "$DRIVE_NAME" -a "`readlink /dev/cdrom`" ]; then + echo -n "Chmoding cdrom device..." + chmod 0666 /dev/cdrom + chmod 0666 /dev/dvd + chmod 0666 /dev/$DRIVE_NAME + status +fi + +# Handle kernel cmdline parameter modprobe= +if [ -n "$MODPROBE" ]; then + MODULES=`sed -e 's/.* modprobe=\([^ ]*\).*/\1/' -e 's/,/\n/g' < /proc/cmdline` + for i in $MODULES; do + echo -n "Loading kernel module $i" + /sbin/modprobe $i + status + done +fi + +# Handle kernel cmdline parameter config=, to source a +# disk init script +if [ -n "$CONFIG" ]; then + DEVICE=${CONFIG%,*} + SCRIPT=${CONFIG#*,} + echo "Probing $DEVICE... " + if ! /bin/mount -r $DEVICE /mnt; then + if echo $DEVICE | grep -Eq "/dev/sd|UUID=|LABEL="; then + USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use` + USBDELAY=$((1+$USBDELAY)) + echo "$DEVICE is potentially a USB device: sleep for $USBDELAY seconds" + sleep $USBDELAY + fi + if ! /bin/mount -r $DEVICE /mnt; then + CONFIG="" + fi + fi + echo -n "Source $SCRIPT from $DEVICE..." + if [ -n "$CONFIG" ]; then + . /mnt/$SCRIPT + /bin/umount /mnt 2> /dev/null || true + fi + status +fi + +# Mount /proc/bus/usb. +if [ -d /proc/bus/usb ]; then + echo -n "Mounting /proc/bus/usb filesystem..." + /bin/mount -t usbfs usbfs /proc/bus/usb + status +fi + +# Start syslogd and klogd. +if [ "$KERNEL_LOG_DAEMONS" = "yes" ]; then + echo -n "Starting system log deamon: syslogd..." + /sbin/syslogd -s $SYSLOGD_ROTATED_SIZE && status + echo -n "Starting kernel log daemon: klogd..." + /sbin/klogd && status +else + echo "Kernel log daemons are disabled in /etc/rc.conf..." +fi + +# Load all modules listed in config file. +if [ -n "$LOAD_MODULES" ]; then + for mod in $LOAD_MODULES + do + modprobe $mod + done +fi + +# Be quiet on configuration to avoid messages overwriting ncurses dialog +echo "0 0 0 0" > /proc/sys/kernel/printk + +# Detect PCI and USB devices with Tazhw from slitaz-tools. We load +# kernel modules only at first boot or in LiveCD mode. +if [ ! -s /var/lib/detected-modules ]; then + /sbin/tazhw init +fi + +# Call udevadm trigger to ensure /dev is fully populate now that all +# modules are loaded. +if [ "$UDEV" = "yes" ]; then + echo -n "Requesting events from the Kernel..." + udevadm trigger + status +fi + +# Start all scripts specified with $RUN_SCRIPTS. +echo "Executing all initialization scripts..." +for script in $RUN_SCRIPTS +do + if [ -x /etc/init.d/$script ]; then + /etc/init.d/$script + fi +done + +# Re-source main config file. In Live mode, daemons list can be modified +# by boot options (screen=text will remove slim). +. /etc/rcS.conf + +# Start all daemons specified with $RUN_DAEMONS. +echo "Starting all daemons specified in /etc/rcS.conf..." +for daemon in $RUN_DAEMONS +do + if [ -x /etc/init.d/$daemon ]; then + /etc/init.d/$daemon start + fi +done + +# Back to a verbose mode. +echo "7 4 1 7" > /proc/sys/kernel/printk + +# Reset screen and display a bold message. +if [ -n "$MESSAGE" ]; then + /usr/bin/reset + #echo -e "\033[1m$MESSAGE\033[0m" +fi + +# Display and log boot time. +time=$((`date +%s` - $bootdate)) +echo $time > /var/log/boot-time +#echo "SliTaz boot time: ${time}s" + +fi # logged diff -r d7f371bbe726 -r 2d20f72ffb19 base-scripts/setup --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base-scripts/setup Tue Nov 01 09:23:49 2011 +0100 @@ -0,0 +1,232 @@ +#!/bin/sh +# Tazadmin - SliTaz System Configuration +# +# +# Author : Eric Joseph-Alexandre (Erjo) +# + +#export DIALOGRC=$PWD/rc/slackware.rc + +VERSION=1.0 + +: ${DIALOG=dialog} + +BACKTITLE="SliTaz Configuration Tools v.${VERSION}" +COMMAND=$1 +LOG=/tmp/$(basename $0).log +OUT=/tmp/_retval_ +DATADIR=/usr/share/slitaz-tools/tazadmin/ +#DATADIR=./ + +BS="15 50" + +# Messages language setting +# Switch to default English if $LANG.msg doesn't exist. +set_locale() +{ + if [ -f ${LANG%%_*}.msg ]; then + . ${DATADIR}${LANG%%_*}.msg + fi +} + +# use --msgbox. +# syntax: msg ["Title"] "Message text" +msg() +{ + if [ $# -gt 1 ]; then + TITLE=$1 + shift + MSG="$@" + else + MSG="$@" + fi + $DIALOG --title " ${TITLE:-Message} " \ + --colors --backtitle "$BACKTITLE" \ + --clear --msgbox "\n$MSG" 0 0 +} + +# Exit install if user is not root. +check_root() +{ + if test $(id -u) != 0 ; then + error_message "$ERR_CHK_ROOT" + exit 0 + fi +} + +# functions +# +trim(){ + read LINE + echo $LINE +} + +get_argc() +{ + echo $# +} + + + + +get_hostname() +{ + # Set hostname + HOSTNAME=$(cat /etc/hostname) + exec 3>&1 + HOSTNAME=`$DIALOG --backtitle "$BACKTITLE" --title "Hostname" --clear \ + --inputbox "Enter your computer hostname" $BS "${HOSTNAME}" 2>&1 1>&3` + ret=$? + exec 3>&- + # if $HOSTNAME is set we update /etc/hostname + # and change current hostname. + if [ ! -z ${HOSTNAME} ]; then + echo ${HOSTNAME} > /etc/hostname + hostname $(cat /etc/hostname) + fi +} + +set_ip_adress() +{ + # Set static configuration for Network. + . /etc/network.conf + exec 3>&1 + IPCONFIG=`$DIALOG --ok-label "Submit" \ + --backtitle "$BACKTITLE" --extra-button --extra-label "${BTN_DHCP:-Use DHCP server}"\ + --title " IP configuration " \ + --form "Here is a possible piece of a configuration program." \ + 20 55 0 \ + "Interface : " 1 1 "$INTERFACE" 1 21 20 0 \ + "IP Address : " 2 1 "$IP" 2 21 20 0 \ + "Network mask : " 3 1 "$NETMASK" 3 21 20 0 \ + "Default gateway : " 4 1 "$GATEWAY" 4 21 20 0 \ + "DNS server(s) : " 5 1 "$DNS_SERVER" 5 21 20 0 \ + 2>&1 1>&3` + ret=$? + exec 3>&- + + case "$ret" in + 0) + if [[ "`get_argc $IPCONFIG`" -gt "1" ]]; then + set_static_ip $IPCONFIG + else + msg "${ERR_BED_IP:-Invalid values.}" + fi + ;; + 3) + get_dhcp_lease ;; + esac +} + +get_dhcp_lease() +{ + sed -i 's/DHCP=.*/DHCP="yes"/' /etc/network.conf + sed -i 's/STATIC=.*/STATIC="no"/' /etc/network.conf + /sbin/udhcpc -b -i $INTERFACE -p /var/run/udhcpc.$INTERFACE.pid & +} + +set_static_ip() +{ + sed -i 's/DHCP=.*/DHCP="no"/' /etc/network.conf + sed -i 's/STATIC=.*/STATIC="yes"/' /etc/network.conf + sed -i -e "s/INTERFACE=".*"/INTERFACE=\"$1\"/" /etc/network.conf + sed -i -e "s/IP=".*"/IP=\"$2\"/" /etc/network.conf + sed -i -e "s/NETMASK=".*"/NETMASK=\"$3\"/" /etc/network.conf + sed -i -e "s/GATEWAY=".*"/GATEWAY=\"$4\"/" /etc/network.conf + sed -i -e "s/DNS_SERVER=".*"/DNS_SERVER=\"$5\"/" /etc/network.conf +} + +network_menu() +{ + ret=0 + until [ $ret -eq 1 ];do + $DIALOG --title "$MENU_TITLE" \ + --backtitle "$BACKTITLE" --clear \ + --cancel-label "Quitter" \ + --colors \ + --menu "$TAZ_CMD_MSG" 15 50 40\ + "adress" " Network settings" \ + "hostname" " Set your hostname" \ + 2> $OUT + ret=$? + case `cat $OUT` in + hostname) + get_hostname ;; + adress) + set_ip_adress ;; + esac + done +} + +set_password() +{ + SEP=' +' + exec 3>&1 + PASSWORD=`$DIALOG --backtitle "$BACKTITLE" --title "Set password" --clear \ + --separate-widget "$SEP" \ + --insecure --passwordbox "Enter new password for user below: \n\n" 10 50 \ + --title "Confirme password" \ + --insecure --passwordbox "Confirme new password for user below: \n\n" 10 50 2>&1 1>&3` + ret=$? + exec 3>&- + if [ -z "${PASSWORD}" ]; then + msg "Password not set" + else + PASS1="$(echo $PASSWORD | cut -d ' ' -f1)" + PASS2="$(echo $PASSWORD | cut -d ' ' -f2)" + if [ "$PASS1" != "$PASS2" ]; then + msg "Passwords don't match.\nNothing change." + else + echo "root:$PASS1" | chpasswd + fi + fi +} + +## +# Program sequence +# +set_locale +check_root + +until [ $retval -eq 1 ];do + $DIALOG --title "$MENU_TITLE" \ + --backtitle "$BACKTITLE" --clear \ + --cancel-label "Quitter" \ + --colors \ + --menu "$TAZ_CMD_MSG" 15 50 40\ + "keymap" " Keyboard mapping" \ + "locale" " Language setting" \ + "network" " Netwok configuration" \ + "password" " Change root password" \ + 2> $OUT + + retval=$? + + # Execute commands + # + case `cat $OUT` in + keymap) + if [ -x /sbin/tazkeymap ]; then + tazkeymap + else + msg "Unable to find tazkeymap !" + fi + ;; + locale) + if [ -x /sbin/tazlocale ]; then + tazlocale + else + msg "Unable to find tazlocale !" + fi + ;; + network) + network_menu;; + password) + set_password ;; + esac +done + +clear + +exit 0 diff -r d7f371bbe726 -r 2d20f72ffb19 base-scripts/vz --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base-scripts/vz Tue Nov 01 09:23:49 2011 +0100 @@ -0,0 +1,604 @@ +#!/bin/sh +# Copyright (C) 2000-2008, Parallels, Inc. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# +# OpenVZ startup script, used for redhat and debian related distributions. + +### +# description: OpenVZ startup script. +### + +VZCONF=/etc/vz/vz.conf + +[ -f ${VZCONF} ] || exit 0 +. ${VZCONF} +[ "${VIRTUOZZO}" = "no" ] && exit 0 + +VZCTL=/usr/sbin/vzctl +[ -x ${VZCTL} ] || exit 0 + +VZQUOTA=/usr/sbin/vzquota +CONFIG_DIR=/etc/vz/conf +LOCKFILE=/var/lock/subsys/vz_lock +SUBSYS_VZ=/var/lock/subsys/vz +VESTAT=/proc/vz/vestat +VZDEV=venet0 +PRELOAD_MODULES= +MODULES= +MODULES_OTHER= +NET_MODULES= +IPT_MODULES= + +if [ "${MODULES_DISABLED}" != "yes" ]; then + PRELOAD_MODULES="af_packet" + MODULES="vzmon vzdquota vzdev" + CPT_MODULES="vzcpt vzrst" + MODULES_OTHER="vzcompat ${CPT_MODULES}" + VNET_MODULES="vznetdev vznet" + VETH_MODULES="vzethdev" + NET_MODULES="${VNET_MODULES} ${VETH_MODULES}" + if [ "${VZWDOG}" = "yes" ]; then + MODULES="${MODULES} vzwdog" + fi + IPT_MODULES="ip_tables ${IPTABLES} xt_tcpudp" + if [ "${IPV6}" = "yes" ]; then + IPT_MODULES="${IPT_MODULES} ${IP6TABLES}" + fi + VZFS_MODULES="simfs" +fi + + +rc_done='..done' +rc_failed='..failed' + +# Source function library. +if [ -r /etc/init.d/functions ]; then + source /etc/init.d/functions + if [ -r /etc/redhat-release ] || [ -r /etc/centos-release ]; then + DISTR=redhat + fi +elif [ -r /etc/rc.status ]; then + source /etc/rc.status + if [ -r /etc/SuSE-release ]; then + DISTR=suse + fi +elif [ -r /etc/debian_version ]; then + DISTR=debian + LOCKFILE=/var/lock/vz_lock + SUBSYS_VZ=/var/lock/vz +elif [ -r /etc/slitaz-release ]; then + DISTR=slitaz + LOCKFILE=/var/lock/vz_lock + SUBSYS_VZ=/var/lock/vz +fi + +VEINFO="" +RETVAL=0 +# Number of the containers to stop in parallel. +# In case of empty value the number of CTs is calculated as 'num_cpu * 4' +PARALLEL= +cd / + +# We used to install OpenVZ cron job when the vzctl package was +# installed, irrespective of whether OpenVZ was actually being +# run. Although the cron jobs didn't create any problems if someone +# wasn't running OpenVZ some users complained about the cron log file +# filling up, resource usage, and power consumption since systems +# wouldn't really idle. It really only makes sense to run the OpenVZ +# cron job if the vz service is turned on and not just merely +# having the package installed. This init.d script is an obvious place +# to install or remove the cron jobs based on the service +# being enabled or not. +SRC_CRONSCRIPT_DIR=/etc/vz/cron +DST_CRONSCRIPT_DIR=/etc/cron.d + +check_old_cron_files() +{ + # avoid double OpenVZ cron settings + local f + for f in vpsreboot vpsnetclean; do + [ -f $DST_CRONSCRIPT_DIR/$f ] && rm -f $DST_CRONSCRIPT_DIR/$f + done +} + +setup_cron() +{ + check_old_cron_files + [ -z "$SRC_CRONSCRIPT_DIR" ] && return + [ -d "$SRC_CRONSCRIPT_DIR" ] || return + cat $SRC_CRONSCRIPT_DIR/vz* > $DST_CRONSCRIPT_DIR/vz && + chmod 644 $DST_CRONSCRIPT_DIR/vz +} + +remove_cron() +{ + check_old_cron_files + [ -z "$SRC_CRONSCRIPT_DIR" ] && return + [ -d "$SRC_CRONSCRIPT_DIR" ] || return + cat > $DST_CRONSCRIPT_DIR/vz <= 2.6.9 VZ_DEV must be set. + test "${KERNEL_MINOR}" -ge 6 && + test "${KERNEL_PATCHLEVEL}" -gt 9 && + opt_must="${opt_must} VZ_DEV" +# local opt_rec="SCHED_VCPU FAIRSCHED VZ_QUOTA VZ_QUOTA_UGID VE_NETDEV VE_ETHDEV +# VE_IPTABLES VZ_CHECKPOINT VZ_WDOG" + + conf="`zcat /proc/config.gz 2>/dev/null | grep -E -v '^#|^$'`" + + for opt in $opt_must; do + if ! echo "$conf" 2>/dev/null | grep -q "$opt="; then + echo "ERROR: Missing kernel config option: CONFIG_$opt" + err=1 + fi + done + if [ $err != 0 ]; then + print_failure "Please recompile your kernel." + exit 1 + fi +} + +get_parallel() +{ + [ -n "${PARALLEL}" ] && return + PARALLEL=`awk ' +BEGIN { num=0; } +$1 == "processor" { num++; } +END { print num * 4; }' /proc/cpuinfo` +} + +get_veinfo() +{ + if [ -f /proc/vz/veinfo ]; then + VEINFO=/proc/vz/veinfo + elif [ -f /proc/veinfo ]; then + VEINFO=/proc/veinfo + elif [ ! -f $VESTAT ]; then + return 1 + fi + return 0 +} + +print_success() +{ + if [ "$DISTR" = "redhat" ]; then + echo_success + else + echo -n "$rc_done" + fi + echo +} + +print_failure() +{ + echo -n "$1" + if [ "$DISTR" = "redhat" ]; then + failure $"$1" + else + echo -n "$rc_failed" + fi + echo +} + +# Calls either print_success or print_failure, depending on $? +# Optional argument $1 -- an error string passed to print_failure. +print_result() +{ + if [ $? -eq 0 ] ; then + print_success + else + print_failure "$1" + fi +} + +__echo() +{ + if [ "$DISTR" = "redhat" ]; then + echo -n $"$1" + else + echo -n "$1" + fi +} + +is_running() +{ + get_veinfo || return 1 + [ -f $SUBSYS_VZ ] || return 1 +} + +status() +{ + check_kernel + + if is_running; then + echo "OpenVZ is running..." + return 0 + else + echo "OpenVZ is stopped." + return 3 + fi +} + +start_net() +{ + local mod + + # load all kernel modules needed for containers networking + for mod in ${NET_MODULES}; do + modprobe ${mod} 2>/dev/null + done + + if ip addr list | grep -q "venet0:.*UP" 2>/dev/null; then + return 0 + fi + + get_veinfo + if [ -z "$VEINFO" ]; then + return 0 + fi + __echo "Bringing up interface $VZDEV: " + ip link set $VZDEV up + print_result + ip addr add 0.0.0.0/0 dev $VZDEV + __echo "Configuring interface $VZDEV: " + sysctl -w net.ipv4.conf.$VZDEV.send_redirects=0 + print_result + if [ "${IPV6}" = "yes" ]; then + __echo "Configuring ipv6 $VZDEV: " + # Fix me: ip addres should be generated + ip -6 addr add fe80::1/128 dev $VZDEV + print_result + fi +} + +stop_net() +{ + local mod + + if ip addr list | grep -q "venet0:.*UP" 2>/dev/null; then + __echo "Bringing down interface $VZDEV: " + ip link set $VZDEV down + print_result + fi + for mod in ${NET_MODULES}; do + /sbin/modprobe -r ${mod} > /dev/null 2>&1 + done +} + +setup_ve0() +{ + if test -z "${VE0CPUUNITS}"; then + echo "Warning: VE0CPUUNITS is not set in ${VZCONF}; using value of 1000" + VE0CPUUNITS=1000 + fi + msg=`${VZCTL} set 0 --cpuunits ${VE0CPUUNITS} 2>&1` + if [ $? -ne 0 ]; then + print_failure "vzctl set 0 --cpuunits ${VE0CPUUNITS} failed: $msg" + fi + + if ! test -f "${CONFIG_DIR}/0.conf"; then + return + fi + if ! grep -q '^ONBOOT=yes\|^ONBOOT=\"yes\"' ${CONFIG_DIR}/0.conf; + then + return + fi + __echo "Configure node UB resources: " + msg=`$VZCTL set 0 --reset_ub 2>&1` + print_result "$msg" +} + +start_ves() +{ + local veid + local velist + local msg + local need_restart + + need_restart="" + cd ${CONFIG_DIR} || return + velist=`grep -l '^ONBOOT=yes\|^ONBOOT=\"yes\"' [0-9]*.conf 2>/dev/null | + sed -e 's/.conf//g' | sort -n` + cd - >/dev/null + sysctl -w net.ipv4.route.src_check=0 + for veid in $velist; do + [ "${veid}" = "0" ] && continue + __echo "Starting CT ${veid}: " + if [ "x${VZFASTBOOT}" = "xyes" -a "x${DISK_QUOTA}" = "xyes" ]; + then + $VZQUOTA stat ${veid} >/dev/null 2>&1 + if [ $? -eq 6 ]; then + if $VZQUOTA show ${veid} 2>&1 | grep "vzquota : (warning) Quota is running" >/dev/null 2>&1; then + $VZQUOTA on ${veid} --nocheck >/dev/null 2>&1 + need_restart="${need_restart} ${veid}" + fi + fi + fi + msg=`$VZCTL start ${veid} 2>&1` + print_result "$msg" + done + for veid in ${need_restart}; do + __echo "Stopping CT ${veid}: " + $VZCTL stop ${veid} 2>&1 >/dev/null 2>&1 + print_result "$msg" + __echo "Starting CT ${veid}: " + msg=`$VZCTL start ${veid} 2>&1` + print_result "$msg" + done +} + +stop_ves() +{ + local veid + local velist + local msg + local m + local mounts + local fail + local iter + local quota + local pids + + if get_veinfo; then + get_parallel + for i in 0 1 2; do + iter=0; + pids= + velist=`awk '$1 != "VEID" && $1 != "Version:" {print $1}' ${VESTAT}` + for veid in $velist; do + echo "Shutting down CT $veid" + # Set fairsched parameters to maximum so + # CT will stop fast + $VZCTL set $veid --cpuunits 2000 --cpulimit 0 >/dev/null 2>&1 + $VZCTL --skiplock stop $veid >/dev/null 2>&1 & + pids="$pids $!" + iter=$(($iter+1)) + if [ ${iter} -gt ${PARALLEL} ]; then + for pid in ${pids}; do + wait ${pid} + done + pids= + iter=0 + fi + done + for pid in $pids; do + wait $pid + done + done + fi + iter=0 + fail=1 + while test $iter -lt 5 -a $fail -ne 0; do + fail=0 + mounts=`awk '{if ($3=="simfs") print $2}' /proc/mounts` + for m in $mounts; do + __echo "Unmounting CT area " + echo -n $m + msg=`umount $m 2>&1` + if [ $? -eq 0 ]; then + print_success + else + print_failure "$msg" + fail=$((fail+1)) + fuser -k -m ${m} > /dev/null 2>&1 + fi + done + iter=$(($iter+1)) + done + # turn quota off + quota=`awk -F: '/^[0-9]+:/{print $1}' /proc/vz/vzquota 2>/dev/null` + for m in ${quota}; do + __echo "Turn quota off for CT " + echo -n $m + msg=`vzquota off ${m} 2>&1` + print_result "$msg" + done +} + +lockfile() +{ + local TEMPFILE="${1}.$$" + local LOCKFILE="${1}" + + trap -- "rm -f ${LOCKFILE} ${TEMPFILE}" EXIT + + echo $$ > ${TEMPFILE} 2> /dev/null || { + echo "Can't write to ${TEMPFILE}" + } + ln ${TEMPFILE} ${LOCKFILE} >/dev/null 2>&1 && { + rm -f ${TEMPFILE}; + return 0; + } + kill -0 `cat $LOCKFILE` >/dev/null 2>&1 && { + return 1; + } + ln ${TEMPFILE} ${LOCKFILE} >/dev/null 2>&1 && { + rm -f ${TEMPFILE}; + return 0; + } + rm -f ${LOCKFILE} + echo $$ > ${LOCKFILE} + return 0 +} + +start() +{ + local veid + local velist + local msg + local mod + + check_kernel + check_kernel_config + + if ! lockfile $LOCKFILE; then + __echo "OpenVZ is locked" + print_failure + return 1 + fi + if [ -f ${SUBSYS_VZ} ]; then + __echo "OpenVZ already running" + print_failure + return 1 + fi + __echo "Starting OpenVZ: " + load_modules "${IPT_MODULES}" + for mod in $PRELOAD_MODULES; do + /sbin/modprobe -r $mod >/dev/null 2>&1 + /sbin/modprobe $mod >/dev/null 2>&1 + done + for mod in $MODULES; do + /sbin/modprobe $mod >/dev/null 2>&1 + RETVAL=$? + if [ $RETVAL -ne 0 ]; then + print_failure "failed to load module ${mod}" + return $RETVAL + fi + done + load_modules "${MODULES_OTHER} ${VZFS_MODULES}" + print_success "loading OpenVZ modules" + + if [ ! -e /dev/vzctl ]; then + # On most modern distros udev will create a device for you, + # while on the old distros /dev/vzctl comes with vzctl rpm. + # So the below mknod call is probably not needed at all. + /bin/mknod -m 600 /dev/vzctl c 126 0 > /dev/null 2>&1 + RETVAL=$? + if [ $RETVAL -ne 0 ]; then + print_failure "creating /dev/vzctl" + return $RETVAL + fi + fi + + start_net + setup_ve0 + setup_cron + start_ves + + rm -f $LOCKFILE + touch $SUBSYS_VZ +} + +stop() +{ + local mod + + if ! lockfile $LOCKFILE; then + __echo "OpenVZ is locked" + print_failure + RETVAL=1 + return 1 + fi + + stop_ves + remove_cron + stop_net + __echo "Stopping OpenVZ: " + for mod in ${MODULES_OTHER} ${MODULES} ${PRELOAD_MODULES} ${IPT_MODULES} ${VZFS_MODULES}; do + /sbin/modprobe -r ${mod} > /dev/null 2>&1 + done + rm -f $LOCKFILE + rm -f $SUBSYS_VZ + print_success +} + +load_modules() +{ + local modules=$1 + local mod + + for mod in ${modules}; do + if /sbin/lsmod | grep -qw ${mod}; then + continue + fi + /sbin/modprobe ${mod} >/dev/null 2>&1 + done +} + +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart|force-reload) + stop + start + ;; + status) + status + RETVAL=$? + ;; + update-cron) + update_cron + RETVAL=0 + ;; + *) + echo "Usage: $0 {start|stop|status|restart|force-reload|update-cron}" + exit 1 +esac + +exit $RETVAL diff -r d7f371bbe726 -r 2d20f72ffb19 base-scripts/vzconf.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base-scripts/vzconf.sh Tue Nov 01 09:23:49 2011 +0100 @@ -0,0 +1,53 @@ +#!/bin/sh +# Set network bridge for OpenVZ server +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. +# +# 20011 - Eric Joseph-Alexandre + + +CONFIG_DIR=/var/lib/slitaz-vz + +# Get real network device name from stored config if exist. +if [ -f $CONFIG_DIR/network/interfaces ]; then + BRIDGE=$(grep ^BRIDGE $CONFIG_DIR/network/interfaces | sed 's/.*"\(.*\)"/\1/') + IFACE=$(grep ^INTERFACE $CONFIG_DIR/network/interfaces | sed 's/.*"\(.*\)"/\1/') +else + BRIDGE=br0 + IFACE=$(grep ^INTERFACE /etc/network.conf | sed 's/.*"\(.*\)"/\1/') + + # Store interface infos for the next boot in hd mode + mkdir -p $CONFIG_DIR/network + echo "BRIDGE=\"$BRIDGE\"" > $CONFIG_DIR/network/interfaces + echo "INTERFACE=\"$IFACE\"" >> $CONFIG_DIR/network/interfaces +fi + +# Set Brigde configuration +if [ -x /usr/sbin/brctl ]; then + if (/usr/sbin/brctl addbr $BRIDGE); then + /sbin/ifconfig $IFACE down + /sbin/ifconfig $IFACE 0 + /usr/sbin/brctl addif $BRIDGE $IFACE + + # Update INTERFACE in /etc/network.conf + grep ^INTERFACE /etc/network.conf | grep -q $BRIDGE \ + || sed -i "s/^INTERFACE=\"\(.*\)\"/INTERFACE=\"$BRIDGE\"/" /etc/network.conf + else + echo "Unable to set netwok bridge" + fi +else + echo "Can't find brctl. Make sure you have installed brctl-utils" +fi