summaryrefslogtreecommitdiff
path: root/i/pc104/initrd/update.sh
diff options
context:
space:
mode:
Diffstat (limited to 'i/pc104/initrd/update.sh')
-rwxr-xr-xi/pc104/initrd/update.sh61
1 files changed, 44 insertions, 17 deletions
diff --git a/i/pc104/initrd/update.sh b/i/pc104/initrd/update.sh
index 1fe8c58..d04a125 100755
--- a/i/pc104/initrd/update.sh
+++ b/i/pc104/initrd/update.sh
@@ -20,19 +20,21 @@ ROBOT_MAX_SIZE="4000000"
# Hostname of the robot
ROBOT_HOST="nenuphar"
# In autonomous mode, wait time for bringing up the ssh deamon
-ROBOT_WAIT_TIME="3s"
+ROBOT_WAIT_TIME="2.5s"
# Compression
ROBOT_NOCOMPRESS=0
# Quiet ?
ROBOT_QUIET=0
# SSH options
-ROBOT_SSH_OPTS="-o \"ConnectionAttempts 4\" -o \"ConnectTimeout 1\""
+ROBOT_SSH_OPTS="-o ConnectTimeout 1"
+# Force autonomous mode
+ROBOT_FORCE_AUTONOMOUS=0
if [ $# -gt 6 ]
then
usage
fi
-while getopts "b:s:r:zqh" option
+while getopts "b:s:r:zaqh" option
do
case $option in
b) ROBOT_BUILD_DIR="$OPTARG";;
@@ -40,6 +42,7 @@ do
s) ROBOT_CONF_MAX_SIZE="$OPTARG";;
r) ROBOT_HOST="$OPTARG";;
z) ROBOT_NOCOMPRESS=1;;
+ a) ROBOT_FORCE_AUTONOMOUS=1;;
q) ROBOT_QUIET=1;;
h) help_initrd;;
\?) help_initrd;;
@@ -86,6 +89,7 @@ usage ()
echo " -s <size> : size max of binaries and config (in bytes)"
echo " -r <host> : robot host"
echo " -z : disable compression"
+ echo " -z : force automous mode (for second update)"
echo " -q : be quiet (expect for errors)"
echo " -h : this message"
exit
@@ -114,7 +118,8 @@ check_create_structure ()
# Create a default one
cat <<EOF > $ROBOT_LOCAL_DIR/$ROBOT_START_SCRIPT
# Startup script launched when the PC104 boot.
-# It will be sourced by other script.
+# It will be executde by other script.
+# IMPORTANT : the commande must begin with a "./" !
# Example :
# ./test_ai -z
EOF
@@ -123,6 +128,15 @@ EOF
log_error "Please tune your $ROBOT_LOCAL_DIR/$ROBOT_START_SCRIPT"
# XXX vim it ?
exit 2
+ else
+ # A little bit of cleaning
+ for file in $ROBOT_LOCAL_DIR/*
+ do
+ if [[ ! -d $file && $file != "$ROBOT_LOCAL_DIR/$ROBOT_START_SCRIPT" ]]
+ then
+ rm -f $file
+ fi
+ done
fi
log "Ok" 3
}
@@ -150,7 +164,12 @@ check_install_binary ()
# Remove useless symbol
strip -p $ROBOT_LOCAL_DIR/$bin
# Copy needed libraries
- for lib in "$(ldd $ROBOT_BUILD_DIR/$bin | cut -d ' ' -f 3)"
+ for lib in $(ldd $ROBOT_BUILD_DIR/$bin | cut -d ' ' -f 3)
+ do
+ cp -p $lib $ROBOT_LOCAL_DIR/lib
+ done
+ # For the one that begins with a /
+ for lib in $(ldd $ROBOT_BUILD_DIR/$bin | grep -E "^[[:space:]]*/" | cut -f 2 |cut -f 1 -d ' ')
do
cp -p $lib $ROBOT_LOCAL_DIR/lib
done
@@ -217,6 +236,9 @@ upload_data ()
ROBOT_AUTONOMOUS=0
# Are we in automous mode ?
log "Autonomous mode" 2
+ if (( $ROBOT_FORCE_AUTONOMOUS == 1 )); then
+ ROBOT_AUTONOMOUS=1
+ fi
nc -w 1 $ROBOT_HOST 1234 > /dev/null 2>&1
if [[ $? -eq 0 ]]
then
@@ -231,44 +253,49 @@ upload_data ()
log "Mouting the initrd" 2
if (( $ROBOT_AUTONOMOUS == 1 )); then
- ssh $ROBOT_SSH_OPTS root@$ROBOT_HOST "\
- mount -oremount,rw / && \
- gunzip -f -c /initrd/last > /tmp/initrd_cur && \
- mount -o loop /tmp/initrd_cur /mnt/initrd"
+ ssh "$ROBOT_SSH_OPTS" root@$ROBOT_HOST "\
+ gunzip -f -c /initrd/last > /dev/shm/initrd_cur && \
+ mount -o loop /dev/shm/initrd_cur /mnt/initrd"
else
- false
# TODO not implemented yet
+ log "Not implemented..." 3
fi
log "Ok" 3
# Rsync data
- log "Rsyncing data"
+ log "Rsyncing data" 2
rsync -au $ROBOT_LOCAL_DIR/ root@$ROBOT_HOST:/mnt/initrd/$ROBOT_REMOTE_DIR/
log "Ok" 3
# Démonter et recompresser l'initrd voir rotater tout
# TODO Backup, rotation, et less cp !
- log "Umounting the initrd and move it" 2
if (( $ROBOT_AUTONOMOUS == 1 )); then
if (( $ROBOT_NOCOMPRESS == 1 )); then
- ssh $ROBOT_SSH_OPTS root@$ROBOT_HOST "\
+ log "Umounting the initrd and move it" 2
+ ssh "$ROBOT_SSH_OPTS" root@$ROBOT_HOST "\
umount /mnt/initrd && \
- mv /tmp/initrd_cur /initrd/initrd1.gz && \
+ mount -oremount,rw / && \
+ mv /dev/shm/initrd_cur /initrd/initrd1.gz && \
+ rm -f /dev/shm/initrd_cur && \
sync && \
mount -oremount,ro / && \
kill -SIGTERM 1"
else
+ log "Umounting the initrd and compress it" 2
# XXX Remove /tmp/initrd_cur after compression ?
- ssh $ROBOT_SSH_OPTS root@$ROBOT_HOST "\
+ ssh "$ROBOT_SSH_OPTS" root@$ROBOT_HOST "\
umount /mnt/initrd && \
- gzip -f -1 -c /tmp/initrd_cur > /initrd/initrd1.gz && \
+ mount -oremount,rw / && \
+ gzip -f -4 -c /dev/shm/initrd_cur > /initrd/initrd1.gz && \
+ rm -f /dev/shm/initrd_cur && \
sync && \
mount -oremount,ro / && \
kill -SIGTERM 1"
fi
else
+ log "Umounting the initrd and move it" 2
# TODO
- false
+ log "Not implemented..." 3
fi
log "Ok... Rebooting" 3
}