mirror of
https://dev.iopsys.eu/iopsys/iopsyswrt.git
synced 2025-12-20 00:52:33 +08:00
The download_extract_bcm() function, used for downloading and extracting BCM toolchains, has been removed. This code is no longer needed after simplifying the download and extraction flow as part of host package.
297 lines
6.5 KiB
Bash
Executable File
297 lines
6.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
arg=$1
|
|
arr_index=0
|
|
declare -a command_array
|
|
declare -a help_array
|
|
|
|
# Check if we should clone feeds with ssh or http
|
|
developer=0
|
|
which git >/dev/null && git remote -v 2>/dev/null | grep -qE '(git@|ssh://)' && developer=1
|
|
|
|
|
|
# Utility functions
|
|
function register_command {
|
|
|
|
command_array[$arr_index]=$1
|
|
help_array[$arr_index]=$2
|
|
arr_index=$((arr_index+1))
|
|
}
|
|
|
|
|
|
function dump_commands {
|
|
for i in $(seq 0 $arr_index); do
|
|
output+=("${command_array[$i]}" "${help_array[$i]}")
|
|
done
|
|
printf "Available commands:\n"
|
|
printf " %-25s%s\n" "${output[@]}" | sort
|
|
printf "\n"
|
|
}
|
|
|
|
# Parse yaml file, look for specified feed definition and create feeds.conf-like output
|
|
function parse_yaml_feed() {
|
|
local yaml_file="$1"
|
|
local feed="$2"
|
|
local yaml_content=$(cat "$yaml_file")
|
|
|
|
# Extract the values
|
|
local names=($(echo "$yaml_content" | grep -oP '(?<=name: ).*'))
|
|
local urls=($(echo "$yaml_content" | grep -oP '(?<=uri: ).*'))
|
|
local revisions=($(echo "$yaml_content" | grep -oP '(?<=revision: ).*'))
|
|
|
|
# Create the output string
|
|
local output=""
|
|
for ((i=0; i<${#names[@]}; i++)); do
|
|
if [ ${names[i]} == ${feed} ]; then
|
|
output+="src-git-full ${names[i]} ${urls[i]}^${revisions[i]}\n"
|
|
fi
|
|
done
|
|
|
|
echo -e "$output"
|
|
}
|
|
|
|
function has_profiles_feed() {
|
|
# regex taken from ./scripts/feeds
|
|
grep -qP '^src-([\w\-]+)((?:\s+--\w+(?:=\S+)?)*)\s+(profiles)' feeds.conf
|
|
}
|
|
|
|
# Register bootstrap command that installs other commands from feeds
|
|
function bootstrap() {
|
|
cp feeds.conf.io feeds.conf
|
|
parse_yaml_feed "profiles/include/iop_feed.yml" iopsys >> feeds.conf
|
|
feeds=(iopsys)
|
|
if has_profiles_feed; then
|
|
feeds+=(profiles)
|
|
fi
|
|
|
|
if [ "$developer" == 1 ]; then
|
|
./scripts/feeds update -g "${feeds[@]}" || exit 1
|
|
else
|
|
./scripts/feeds update "${feeds[@]}" || exit 1
|
|
fi
|
|
|
|
./scripts/feeds install -p iopsys iop || exit 1
|
|
}
|
|
|
|
register_command "bootstrap" "Initial command to run to install other commands"
|
|
|
|
function install_locales()
|
|
{
|
|
sudo locale-gen en_US.UTF-8
|
|
}
|
|
|
|
function install_pkgs()
|
|
{
|
|
local packages_misc="
|
|
bc
|
|
bison
|
|
build-essential
|
|
ccache
|
|
cpio
|
|
curl
|
|
device-tree-compiler
|
|
dialog
|
|
file
|
|
flex
|
|
g++
|
|
g++-multilib
|
|
gawk
|
|
gdisk
|
|
gettext
|
|
git
|
|
automake
|
|
gtk-doc-tools
|
|
jq
|
|
libarchive-zip-perl
|
|
libelf-dev
|
|
liblzo2-dev
|
|
libncurses6
|
|
libncurses-dev
|
|
libssl-dev
|
|
libtool
|
|
ncurses-term
|
|
pv
|
|
python3
|
|
python3-cryptography
|
|
python3-setuptools
|
|
python3-jsonschema
|
|
rsync
|
|
ssh
|
|
subversion
|
|
svn-buildpackage
|
|
swig
|
|
unzip
|
|
uuid-dev
|
|
wget
|
|
zlib1g-dev
|
|
xxd
|
|
cmake
|
|
quilt
|
|
cryptsetup
|
|
libcap-dev
|
|
libseccomp-dev
|
|
libyajl-dev
|
|
coccinelle
|
|
e2fsprogs
|
|
"
|
|
local packages_perl="libconvert-binary-c-perl libdigest-crc-perl"
|
|
|
|
# do we need 32 bit compatibility libs ?
|
|
if [ "$(uname -m | awk '{print$1}')" == "x86_64" ]; then
|
|
local packages_x64="libc6-dev-i386 lib32z1 libncurses6:i386"
|
|
fi
|
|
|
|
# filter out already installed packages
|
|
local packages_all="$packages_misc $packages_perl $packages_x64"
|
|
local needed=""
|
|
|
|
for pkg in $packages_all
|
|
do
|
|
if ! dpkg -s $pkg >/dev/null 2>/dev/null
|
|
then
|
|
needed="$needed $pkg"
|
|
fi
|
|
done
|
|
|
|
# install needed packages
|
|
if [ -n "$needed" ]
|
|
then
|
|
echo "Need to install dpkg packages [$needed]"
|
|
read -p "Do you approve installation of these packages (y/n): " ans
|
|
if [ "$ans" == "y" ]; then
|
|
sudo apt-get update && sudo apt-get install --no-install-recommends $needed || exit $?
|
|
else
|
|
echo "can't continue. aborting!"
|
|
exit 1
|
|
fi
|
|
fi
|
|
}
|
|
|
|
check_bash()
|
|
{
|
|
local mysh=$(ls -hl /bin/sh | awk -F'[ ,/]' '{print$NF}')
|
|
if [ "$mysh" != "bash" ]; then
|
|
echo "On Debian based systems, e.g. Ubuntu, /bin/sh must point to bash instead of $mysh"
|
|
read -p "Do you approve this change (y/n): " ans
|
|
if [ "$ans" == "y" ]; then
|
|
sudo rm -f /bin/sh
|
|
sudo ln -s bash /bin/sh
|
|
else
|
|
echo "Warning! You haven't pointed /bin/sh to bash."
|
|
exit 1
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# Compare modification date of two files
|
|
# return 0 (true) if first file is older, 1 (false) otherwise
|
|
is_older() {
|
|
local target=$(stat -c %Y $1 2> /dev/null)
|
|
local ref=$(stat -c %Y $2 2> /dev/null)
|
|
|
|
[ -z "$target" -o -z "$ref" ] && return 1
|
|
[ $target -lt $ref ] && return 0
|
|
return 1
|
|
}
|
|
|
|
install_iop_completion() {
|
|
local instloc=/usr/share/bash-completion/completions/iop
|
|
local srcloc=./feeds/iopsys/iop/iop.completion
|
|
local inst=0
|
|
|
|
if [ ! -e $instloc ]; then
|
|
echo "Bash completion for './iop' utility not found"
|
|
inst=1
|
|
elif is_older $instloc $srcloc ; then
|
|
echo "Bash completion for './iop' utility is outdated"
|
|
inst=1
|
|
fi
|
|
|
|
if [ $inst -eq 1 ]; then
|
|
read -p "Install latest version to '$instloc' (y/n): " ans
|
|
if [ "$ans" == "y" ]; then
|
|
sudo cp $srcloc $instloc
|
|
echo "Start a new shell to enable ./iop command completion!"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
function setup_host {
|
|
|
|
#===============#
|
|
# Prerequisites #
|
|
#===============#
|
|
|
|
install_locales
|
|
install_pkgs
|
|
check_bash
|
|
install_iop_completion
|
|
|
|
echo ""
|
|
echo ""
|
|
echo "You have successfully installed and configred prerequisites to be able to build an iopsys firmware"
|
|
echo ""
|
|
echo ""
|
|
}
|
|
|
|
register_command "setup_host" "Install needed packets to host machine"
|
|
|
|
|
|
# Plugin scripts call register command to export their interface
|
|
if [ -d package/feeds/iopsys/iop/scripts ]; then
|
|
|
|
for f in package/feeds/iopsys/iop/scripts/*; do
|
|
source $f
|
|
done
|
|
fi
|
|
|
|
function feeds_update {
|
|
|
|
# Call bootstrap to update feeds/iopsys for transiton in old/new genconfig state
|
|
echo "Calling bootstrap to update required feeds"
|
|
bootstrap
|
|
|
|
# always return true
|
|
exit 0
|
|
}
|
|
|
|
register_command "feeds_update" "Compatibility function only"
|
|
|
|
function set-feed-rev() {
|
|
./scripts/set-feed-rev "$@"
|
|
}
|
|
|
|
register_command "set-feed-rev" "Update feeds revisions in feeds.conf.io and profiles"
|
|
|
|
function openwrt() {
|
|
./scripts/openwrt.py "$@"
|
|
}
|
|
|
|
register_command "openwrt" "OpenWRT upstream-related feed manipulation"
|
|
|
|
# Register commands from external files
|
|
source ./scripts/genconfig_wrap.sh
|
|
source ./scripts/iopupgrade.sh
|
|
|
|
if [ -z $arg ] || [ $arg == "--help" ]; then
|
|
printf "Usage: iop <command> [<args>]\n\n"
|
|
dump_commands
|
|
exit 0
|
|
fi
|
|
|
|
# Check all registered commands for a match
|
|
for i in $(seq 0 $arr_index); do
|
|
|
|
if [ $arg == "${command_array[$i]}" ]; then
|
|
# Run the command and pass all args
|
|
# except for the first to it
|
|
$arg "${@:2}"; exit
|
|
fi
|
|
done
|
|
|
|
|
|
# No registered command for the passed input arg
|
|
printf "Error: no such command $arg\n\n"
|
|
dump_commands
|
|
exit 1
|