#!/bin/bash

#apt install clang llvm libasound2-dev libssl-dev
#apt-get install usb-modeswitch usb-modeswitch-data
#apt-get install modemmanager
#sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/clang 100
#sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/clang++ 100
#alsamixer -> F4, turn on mic1 with space


read -p "Input ip: " NANOPI_IP
read -sp "Input ssh password: " SSH_PASSWORD
echo

DEST_DIR="./sysroot"

copy_files() {
    sshpass -p "$SSH_PASSWORD" rsync -avLW --no-p --no-o --no-g --delete root@$NANOPI_IP:$1 $2
}

if ! command -v sshpass &> /dev/null; then
    echo "sshpass not found"
    exit 1
fi

mkdir -p $DEST_DIR/usr

echo "Copying..."

copy_files "/lib" "$DEST_DIR/"
copy_files "/usr/lib" "$DEST_DIR/usr/"
copy_files "/usr/include" "$DEST_DIR/usr/"

#ln -sf $DEST_DIR/usr/lib/arm-linux-gnueabihf/libbrotlicommon.so.1.0.9 $DEST_DIR/usr/lib/arm-linux-gnueabihf/libbrotlicommon.so
#ln -sf $DEST_DIR/usr/lib/arm-linux-gnueabihf/libbrotlidec.so.1.0.9 $DEST_DIR/usr/lib/arm-linux-gnueabihf/libbrotlidec.so
#ln -sf $DEST_DIR/usr/lib/arm-linux-gnueabihf/libbrotlienc.so.1.0.9 $DEST_DIR/usr/lib/arm-linux-gnueabihf/libbrotlienc.so

echo "Success"
