try change file mode to 775

pull/23/head
johndah4x0r 2017-07-28 14:02:50 +02:00 committed by GitHub
parent f9a10045dc
commit c9f386984d
1 changed files with 133 additions and 116 deletions

View File

@ -37,7 +37,7 @@ NC=""
# debug related # debug related
debug_start() debug_start()
{ {
if grep -q debug /proc/cmdline; then if grep -q 'debug' /proc/cmdline; then
DEBUG_IS_ENABLED=1 DEBUG_IS_ENABLED=1
else else
DEBUG_IS_ENABLED= DEBUG_IS_ENABLED=
@ -170,15 +170,15 @@ mkbund()
debug_log "mkbund" "$*" debug_log "mkbund" "$*"
if [ -e "$2" ]; then if [ -e "$2" ]; then
echo_warn "mkbund: `basename $2`: File already exists!" echo_warn "mkbund: $(basename $2): File already exists!"
echo_warn "mkbund: `basemane $2`: Deleting file..." echo_warn "mkbund: $(basename $2): Deleting file..."
rm -f "$2" rm -f "$2"
else else
echo_livekit_msg "mkbund: `basename $2`: Making new bundle..." echo_livekit_msg "mkbund: $(basename $2): Making new bundle..."
fi fi
echo_livekit_msg "mkbund: SquashFS compression: 1024k - XZ" >&2 echo_livekit_msg "mkbund: SquashFS compression: 1024k - XZ" >&2
echo_livekit_msg "mkbund: `basename $2`: Compressing bundle..." >&2 echo_livekit_msg "mkbund: $(basename $2): Compressing bundle..." >&2
mksquashfs "$1" "$2" -comp xz -b 1024k $3 $4 $5 $6 $7 $8 $9 >/dev/null || \ mksquashfs "$1" "$2" -comp xz -b 1024k $3 $4 $5 $6 $7 $8 $9 >/dev/null || \
(echo_err "mkbund: Failed to make bundle!" && exit 1) (echo_err "mkbund: Failed to make bundle!" && exit 1)
} }
@ -201,16 +201,16 @@ cmdline_value()
# #
transfer_initramfs() transfer_initramfs()
{ {
if [ ! -r /lib/initramfs_escaped ]; then if [ ! -r /lib/esc_initramfs.sgn ]; then
echo_livekit >&2 echo_livekit >&2
echo "Switching root from initramfs to tmpfs..." >&2 echo "Switching root from initramfs to tmpfs..." >&2
SWITCH=/m # one letter directory SWITCH=/m # one letter directory
mkdir -p $SWITCH mkdir -p $SWITCH
mount -t tmpfs -o size="100%" tmpfs $SWITCH mount -t tmpfs -o size="100%" tmpfs "$SWITCH"
cp -a /??* $SWITCH 2>/dev/null # only copy two-and-more-letter directories cp -a /??* "$SWITCH" 2>/dev/null # only copy two-and-more-letter directories
cd $SWITCH cd $SWITCH
echo "This file indicates that we successfully escaped initramfs" > $SWITCH/lib/initramfs_escaped echo "This file indicates that we successfully escaped initramfs" >"$SWITCH"/lib/esc_initramfs.sgn
exec switch_root -c /dev/console . $0 exec switch_root -c /dev/console . "$0"
fi fi
} }
@ -219,7 +219,7 @@ transfer_initramfs()
init_proc_sysfs() init_proc_sysfs()
{ {
debug_log "init_proc_sysfs" "$*" debug_log "init_proc_sysfs" "$*"
mkdir -p /proc /sys /etc $MEMORY mkdir -p /proc /sys /etc "$MEMORY"
mount -n -t proc proc /proc mount -n -t proc proc /proc
echo "0" >/proc/sys/kernel/printk echo "0" >/proc/sys/kernel/printk
mount -n -t sysfs sysfs /sys mount -n -t sysfs sysfs /sys
@ -266,14 +266,14 @@ init_devs()
# #
init_zram() init_zram()
{ {
debug_log "init_zram" "$*" debug_log "init_zram" "$*"
echo_livekit_msg "Setting up ZRAM as swap if available..." echo_livekit_msg "Setting up ZRAM as swap if available..."
if [ -r /sys/block/zram0/disksize ]; then if [ -r /sys/block/zram0/disksize ]; then
echo 536870912 > /sys/block/zram0/disksize # 512MB echo 536870912 > /sys/block/zram0/disksize # 512MB
mkswap /dev/zram0 >/dev/null mkswap /dev/zram0 >/dev/null
swapon /dev/zram0 -p 32767 swapon /dev/zram0 -p 32767
echo 100 > /proc/sys/vm/swappiness echo 100 > /proc/sys/vm/swappiness
fi fi
} }
# load the AUFS kernel module if needed # load the AUFS kernel module if needed
@ -281,11 +281,12 @@ init_zram()
init_aufs() init_aufs()
{ {
debug_log "init_aufs" "$*" debug_log "init_aufs" "$*"
# TODO maybe check here if aufs support is working at all
# and produce useful error message if user has no aufs # Prepare for error messages
echo >>/var/log/livkekit-log
modprobe aufs 2>/var/log/livekit-log modprobe aufs 2>/var/log/livekit-log
# TODO ACCOMPLISHED:
# If aufs module failed to load, panic immidiately # If aufs module failed to load, panic immidiately
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
fatal "Failed to load AUFS module!" fatal "Failed to load AUFS module!"
@ -306,7 +307,16 @@ init_union()
echo_livekit_msg "Initialising AUFS union..." echo_livekit_msg "Initialising AUFS union..."
mkdir -p "$1" mkdir -p "$1"
mkdir -p "$2" mkdir -p "$2"
mount -t aufs -o xino="/.xino",trunc_xino,br="$1" aufs "$2"
# Prepare for error messages
echo >>/var/log/livekit-log
mount -t aufs -o xino="/.xino",trunc_xino,br="$1" aufs "$2" >/var/log/livekit-log 2>&1
# If failed to init union, panic
if [ $? -ne 0 ]; then
fatal "Failed to initialise AUFS union!"
fi
} }
# Return device mounted for given directory # Return device mounted for given directory
@ -314,18 +324,18 @@ init_union()
# #
mounted_device() mounted_device()
{ {
debug_log "mounted_device" "$*" debug_log "mounted_device" "$*"
local MNT TARGET local MNT TARGET
MNT="$1" MNT="$1"
while [ "$MNT" != "/" -a "$MNT" != "." -a "$MNT" != "" ]; do while [ "$MNT" != "/" -a "$MNT" != "." -a "$MNT" != "" ]; do
TARGET="$(grep -F " $MNT " /proc/mounts | cut -d " " -f 1)" TARGET="$(grep -F " $MNT " /proc/mounts | cut -d " " -f 1)"
if [ "$TARGET" != "" ]; then if [ "$TARGET" != "" ]; then
echo "$TARGET" echo "$TARGET"
return return
fi fi
MNT="$(dirname "$MNT")" MNT="$(dirname "$MNT")"
done done
} }
# Return mounted dir for given directory # Return mounted dir for given directory
@ -333,17 +343,17 @@ mounted_device()
# #
mounted_dir() mounted_dir()
{ {
debug_log "mounted_dir" "$*" debug_log "mounted_dir" "$*"
local MNT local MNT
MNT="$1" MNT="$1"
while [ "$MNT" != "/" -a "$MNT" != "." -a "$MNT" != "" ]; do while [ "$MNT" != "/" -a "$MNT" != "." -a "$MNT" != "" ]; do
if mountpoint -q "$MNT" 2>/dev/null; then if mountpoint -q "$MNT" 2>/dev/null; then
echo "$MNT" echo "$MNT"
return return
fi fi
MNT="$(dirname "$MNT")" MNT="$(dirname "$MNT")"
done done
} }
# Make sure to mount FAT12/16/32 using vfat # Make sure to mount FAT12/16/32 using vfat
@ -372,14 +382,14 @@ device_bestfs()
# #
fs_options() fs_options()
{ {
debug_log "fs_options" "$*" debug_log "fs_options" "$*"
if [ "$1" = "-t" ]; then if [ "$1" = "-t" ]; then
shift shift
fi fi
if [ "$1" = "vfat" ]; then if [ "$1" = "vfat" ]; then
echo "-o check=s,shortname=mixed,iocharset=utf8" echo "-o check=s,shortname=mixed,iocharset=utf8"
fi fi
} }
@ -391,30 +401,30 @@ fs_options()
# #
init_network_dev() init_network_dev()
{ {
debug_log "init_network_dev" "$*" debug_log "init_network_dev" "$*"
echo_livekit_msg "Preparing networking device(s)..." >&2 echo_livekit_msg "Preparing networking device(s)..." >&2
local MODULE ETH local MODULE ETH
for MODULE in 3c59x acenic de4x5 e1000 e1000e e100 epic100 hp100 \ for MODULE in 3c59x acenic de4x5 e1000 e1000e e100 epic100 hp100 \
ne2k-pci pcnet32 8139too 8139cp tulip via-rhine r8169 atl1e yellowfin \ ne2k-pci pcnet32 8139too 8139cp tulip via-rhine r8169 atl1e yellowfin \
tg3 dl2k ns83820 atl1 b44 bnx2 skge sky2 tulip depca 3c501 3c503 \ tg3 dl2k ns83820 atl1 b44 bnx2 skge sky2 tulip depca 3c501 3c503 \
3c505 3c507 3c509 3c515 ac3200 at1700 cosa cs89x0 de600 de620 e2100 \ 3c505 3c507 3c509 3c515 ac3200 at1700 cosa cs89x0 de600 de620 e2100 \
eepro eexpress eth16i ewrk3 forcedeth hostess_sv11 hp-plus hp ni52 \ eepro eexpress eth16i ewrk3 forcedeth hostess_sv11 hp-plus hp ni52 \
ni65 sb1000 sealevel smc-ultra sis900 smc9194 wd; do ni65 sb1000 sealevel smc-ultra sis900 smc9194 wd; do
modprobe $MODULE 2>/dev/null modprobe $MODULE 2>/dev/null
ETH="$(cat /proc/net/dev | grep : | grep -v lo: | cut -d : -f 1 | tr -d " " | head -n 1)" ETH="$(cat /proc/net/dev | grep : | grep -v lo: | cut -d : -f 1 | tr -d " " | head -n 1)"
if [ "$ETH" != "" ]; then if [ "$ETH" != "" ]; then
echo $ETH echo "$ETH"
return 0 return 0
fi fi
rmmod $MODULE 2>/dev/null rmmod $MODULE 2>/dev/null
done done
# If we are here, none of the above specified modules worked. # If we are here, none of the above specified modules worked.
# As a last chance, try to modprobe everything. # As a last chance, try to modprobe everything.
echo_warn "No networking kernel module found!" echo_warn "No networking kernel module found!"
modprobe_everything modprobe_everything
cat /proc/net/dev | grep : | grep -v lo: | cut -d : -f 1 | tr -d " " | head -n 1 cat /proc/net/dev | grep ':' | grep -v 'lo:' | cut -d : -f 1 | tr -d " " | head -n 1
} }
@ -423,48 +433,52 @@ init_network_dev()
# #
download_data_pxe() download_data_pxe()
{ {
debug_log "download_data_pxe" "$*" debug_log "download_data_pxe" "$*"
local CMD CLIENT SERVER GW MASK PORT ETH PROTOCOL local CMD CLIENT SERVER GW MASK PORT ETH PROTOCOL
mkdir -p "$1/$LIVEKITNAME" mkdir -p "$1/$LIVEKITNAME"
cmdline_value ip | while IFS=":" read CLIENT SERVER GW MASK PORT; do cmdline_value ip | while IFS=":" read CLIENT SERVER GW MASK PORT; do
echo_livekit_msg "Downloading files from $SERVER ..." >&2 echo_livekit_msg "Downloading files from ${SERVER}..." >&2
ETH=$(init_network_dev) ETH=$(init_network_dev)
if [ "$PORT" = "" ]; then PORT="7529"; fi if [ "$PORT" = "" ]; then
PORT="7529"
fi
# set IP address as given by boot paramter # set IP address as given by boot paramter
if [ "$CLIENT" != "" -a "$MASK" != "" ]; then if [ -n "$CLIENT" ] && [ -n "$MASK" ]; then
ifconfig $ETH "$CLIENT" netmask "$MASK" ifconfig $ETH "$CLIENT" netmask "$MASK"
route add default gw "$GW" route add default gw "$GW"
else else
# if client ip is unknown, try to get a DHCP lease # if client ip is unknown, try to get a DHCP lease
udhcpc -i $ETH -f -q udhcpc -i $ETH -f -q
fi fi
# well known IP address of Google public DNS service # well known IP address of Google public DNS service
echo nameserver 8.8.8.8 >> /etc/resolv.conf echo nameserver 8.8.8.8 >> /etc/resolv.conf
PROTOCOL=http PROTOCOL=http
wget -q -O "$1/PXEFILELIST" "http://$SERVER:$PORT/PXEFILELIST?$(uname -r):$(uname -m)" wget -q -O "$1/PXEFILELIST" "http://$SERVER:$PORT/PXEFILELIST?$(uname -r):$(uname -m)"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo_warn "Failed to download from http://$SERVER:$PORT, trying TFTP..." echo_warn "Failed to download from http://${SERVER}:${PORT}!" >&2
PROTOCOL=tftp echo_livekit_msg 'Downloading with TFTP protocol...' >&2
tftp -g -r PXEFILELIST -l "$1/PXEFILELIST" $SERVER PROTOCOL=tftp
fi tftp -g -r PXEFILELIST -l "$1/PXEFILELIST" $SERVER
fi
cat "$1/PXEFILELIST" | while read FILE; do cat "$1/PXEFILELIST" | while read FILE; do
if [ "$PROTOCOL" = "http" ]; then if [ "$PROTOCOL" = "http" ]; then
wget -O "$1/$LIVEKITNAME/$FILE" "http://$SERVER:$PORT/$FILE" echo_livekit_msg "PXE-HTTP: Downloading ${FILE}..." >&2
else wget -O "$1/$LIVEKITNAME/$FILE" "http://$SERVER:$PORT/$FILE"
echo_livekit_msg "PXE: ${FILE}..." >&2 elif [ "$PROTOCOL" = "tftp" ]; then
tftp -g -r $FILE -l "$1/$LIVEKITNAME/$FILE" $SERVER echo_livekit_msg "PXE-TFTP: Downloading ${FILE}..." >&2
fi tftp -g -r $FILE -l "$1/$LIVEKITNAME/$FILE" $SERVER
done fi
done done
done
echo "$1/$LIVEKITNAME" echo "$1/$LIVEKITNAME"
} }
# Find LIVEKIT data by mounting all devices # Find LIVEKIT data by mounting all devices
@ -528,22 +542,25 @@ find_data()
echo_livekit >&2 echo_livekit >&2
echo "Looking for $LIVEKITNAME data in /$FROM .." | tr -s "/" >&2 echo "Looking for $LIVEKITNAME data in /$FROM .." | tr -s "/" >&2
for timeout in $(seq 1 $1); do for timeout in $(seq 1 $1); do
echo -n "." >&2 echo -n "." >&2
refresh_devs refresh_devs
DATA="$(find_data_try "$2" "$FROM")" DATA="$(find_data_try "$2" "$FROM")"
# This "was" a bug!
echo "" >&2
if [ "$DATA" != "" ]; then
echo_livekit_msg "$LIVEKITNAME data found on $(mounted_device "$2")" >&2
echo "$DATA"
return
fi
sleep 1
done
echo "" >&2 echo "" >&2
if [ "$DATA" != "" ]; then
echo_livekit_msg "$LIVEKITNAME data found on $(mounted_device "$2")" >&2
echo "$DATA"
return
fi
sleep 1
done
echo "" >&2
if [ "$DATA" = "" ]; then if [ "$DATA" = "" ]; then
fatal "$LIVEKITNAME data not found" fatal "$LIVEKITNAME data not found"
fi fi
} }