Fix media sync, add files checks

This commit is contained in:
ABelliqueux 2022-10-22 15:04:00 +02:00
parent abb06f9c80
commit 4131ddfb73
1 changed files with 26 additions and 9 deletions

View File

@ -2,7 +2,6 @@
# #
# Options # Options
# Device block to write on # Device block to write on
# TODO : Add flags check
# Colored output # Colored output
#~ set +x #~ set +x
bold=$(tput bold) bold=$(tput bold)
@ -26,19 +25,35 @@ function yellow(){
} }
SDCARD=$1 SDCARD=$1
if [ "$SDCARD" == "" ] # TODO : accomodate for devices block with name mmcblk0p1|p2
if [ "$SDCARD" == "" ] || [ ! -e "$SDCARD" ]
then then
red "Please specify the SDcard device block, e.g: '/dev/mmcblk0'." red "Please specify an existing device block for your sd-card, e.g: '/dev/sda'."
exit 0 exit 0
fi fi
DD_BS="128K" DD_BS="128K"
DISK_IMAGE="$HOME/niels/imgs/2022-10-20-pilpil.img.xz" DISK_IMAGE="$HOME/niels/imgs/2022-10-21-pilpil.img.xz"
if [ ! -f "$DISK_IMAGE" ]
then
red "Disk image not found, aborting..."
exit 0
fi
CONFIG_DIR="$HOME/niels/pilpil-server" CONFIG_DIR="$HOME/niels/pilpil-server"
if [ ! -d "$CONFIG_DIR" ]
then
red "Config directory not found, aborting..."
exit 0
fi
PI_USER="pil" PI_USER="pil"
BOOT_MOUNT="/run/media/$USER/boot" BOOT_MOUNT="/run/media/$USER/boot"
ROOTFS_MOUNT="/run/media/$USER/rootfs" ROOTFS_MOUNT="/run/media/$USER/rootfs"
#~ LOCAL_MEDIA_DIR="$HOME/Videos" #~ LOCAL_MEDIA_DIR="$HOME/Videos"
LOCAL_MEDIA_DIR="$HOME/niels/medias" LOCAL_MEDIA_DIR="$HOME/niels/medias"
if [ ! -d "$LOCAL_MEDIA_DIR" ]
then
red "Medias directory not found, aborting..."
exit 0
fi
REMOTE_MEDIA_DIR="$ROOTFS_MOUNT/home/$PI_USER/Videos" REMOTE_MEDIA_DIR="$ROOTFS_MOUNT/home/$PI_USER/Videos"
IP_RANGE="10.42.0.1" IP_RANGE="10.42.0.1"
SSID="omen" SSID="omen"
@ -135,6 +150,8 @@ do
green "Operation 4/13 : Changing hostname to $HOST_NAME ...\n" green "Operation 4/13 : Changing hostname to $HOST_NAME ...\n"
# Change hostname # Change hostname
echo "$HOST_NAME" | sudo tee "$ROOTFS_MOUNT/etc/hostname" echo "$HOST_NAME" | sudo tee "$ROOTFS_MOUNT/etc/hostname"
# Reflect that in /etc/hosts
sed -i "$ d" "$ROOTFS_MOUNT/etc/hosts"
echo -e "127.0.1.1\t$HOST_NAME" | sudo tee -a "$ROOTFS_MOUNT/etc/hosts" echo -e "127.0.1.1\t$HOST_NAME" | sudo tee -a "$ROOTFS_MOUNT/etc/hosts"
## Enable SSH ## Enable SSH
green "Operation 5/13 : Enabling SSH server on boot ...\n" green "Operation 5/13 : Enabling SSH server on boot ...\n"
@ -148,7 +165,7 @@ do
if [ "$ADD_SSH_CONF" == "y" ] if [ "$ADD_SSH_CONF" == "y" ]
then then
# Add to ~/.ssh/config # Add to ~/.ssh/config
echo -e "Host $HOST\n\tIdentityFile ~/.ssh/$HOST_NAME\n\tUser $PI_USER" | tee -a "$HOME/.ssh/config" echo -e "Host $HOST_NAME\n\tHostName $HOST\n\tIdentityFile ~/.ssh/$HOST_NAME\n\tUser $PI_USER" | tee -a "$HOME/.ssh/config"
fi fi
# Copy public key to rpi # Copy public key to rpi
green "Operation 7/13 : Installing public SSH key $HOME/.ssh/$HOST.pub in $ROOTFS_MOUNT/home/$PI_USER/.ssh/authorized_keys...\n" green "Operation 7/13 : Installing public SSH key $HOME/.ssh/$HOST.pub in $ROOTFS_MOUNT/home/$PI_USER/.ssh/authorized_keys...\n"
@ -201,8 +218,8 @@ network={
then then
USER_ID=$( cat "$ROOTFS_MOUNT/etc/passwd" | grep $PI_USER | awk -F: '{print $3}' ) USER_ID=$( cat "$ROOTFS_MOUNT/etc/passwd" | grep $PI_USER | awk -F: '{print $3}' )
GROUP_ID=$( cat "$ROOTFS_MOUNT/etc/passwd" | grep $PI_USER | awk -F: '{print $4}' ) GROUP_ID=$( cat "$ROOTFS_MOUNT/etc/passwd" | grep $PI_USER | awk -F: '{print $4}' )
sudo cp "$LOCAL_MEDIA_DIR/*" "$REMOTE_MEDIA_DIR/" sudo cp "$LOCAL_MEDIA_DIR/"* "$REMOTE_MEDIA_DIR/"
sudo chown $USER_ID:$GROUP_ID "$REMOTE_MEDIA_DIR/*" sudo chown -R $USER_ID:$GROUP_ID "$REMOTE_MEDIA_DIR"
sync sync
else else
red "Not enough space on $ROOTFS_MOUNT, skipping..." red "Not enough space on $ROOTFS_MOUNT, skipping..."
@ -211,8 +228,8 @@ network={
green "Operation 13/13 : Unmounting filesystems" green "Operation 13/13 : Unmounting filesystems"
umount $BOOT_MOUNT umount $BOOT_MOUNT
umount $ROOTFS_MOUNT umount $ROOTFS_MOUNT
yellow "Client $(($IP-10))/$CLIENT_NUMBER done." yellow "Client $(($IP-9))/$CLIENT_NUMBER done."
if [ $(($IP+1)) -le $(($CLIENT_NUMBER+$IP)) ] if [ $(($IP+1)) -lt $(($CLIENT_NUMBER+$IP)) ]
then then
red "Please swap sd card in reader and enter uppercase 'yes' to proceed with next client :" red "Please swap sd card in reader and enter uppercase 'yes' to proceed with next client :"
read -n 4 GO_ON read -n 4 GO_ON