cc-fw-tools/RESOURCES/OPTIONS/ssh/ssh.sh
2024-02-14 11:27:04 -05:00

65 lines
1.5 KiB
Bash
Executable file

#!/bin/bash
# global definitions:
RED='\033[0;31m'
NC='\033[0m'
# check the parameters
if [ $# != 2 ]; then
echo "usage : $0 <project_root> <ssh_package>"
exit 1
fi
project_root="$1"
ssh_package=$(echo "$2" | sed -e 's/^"//' -e 's/"$//')
# check the required tools
TOOL_LIST=("unzip")
i=0
part_num=${#TOOL_LIST[*]}
while [ $i -lt $((part_num)) ]; do
echo "Checking tool: ${TOOL_LIST[$i]}"
t=$(which "${TOOL_LIST[$i]}")
if [ -z "$t" ]; then
if [ ! -f "TOOLS/${TOOL_LIST[$i]}" ]; then
echo -e "${RED}ERROR: Missing tool '${TOOL_LIST[$i]}' ${NC}"
exit 2
fi
fi
i=$(($i + 1))
done
# check the project root folder
if [ ! -d "$project_root" ]; then
echo -e "${RED}ERROR: Cannot find the folder '$project_root' ${NC}"
exit 3
fi
# check the ssh package folder
ssh_package_folder="${project_root}/RESOURCES/OPTIONS/ssh/${ssh_package}"
if [ ! -d "$ssh_package_folder" ]; then
echo -e "${RED}ERROR: Cannot find the folder '$ssh_package_folder' ${NC}"
exit 4
fi
# check the ssh package file
ssh_package_file="${ssh_package_folder}/${ssh_package}.zip"
if [ ! -f "$ssh_package_file" ]; then
echo -e "${RED}ERROR: Cannot find the file '$ssh_package_file' ${NC}"
exit 5
fi
# check the target folder
target_folder="$project_root/unpacked/squashfs-root"
if [ ! -d "$target_folder" ]; then
echo -e "${RED}ERROR: Cannot find the target folder '$target_folder' ${NC}"
exit 6
fi
# enable the selected ssh package
current_folder="$PWD"
cd "$target_folder" || exit 7
unzip -o "$ssh_package_file"
cd "$current_folder" || exit 8
exit 0