加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
hardware_manage 35.60 KB
一键复制 编辑 原始数据 按行查看 历史
darcyg 提交于 2015-06-19 12:19 . 增加分支管理/版本下载等功能
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
#!/bin/bash
source common/common.sh common
function get_config_var()
{
local ppath=$(get_profile_path)
[ -f $ppath ] && cfg=$(cat $ppath) || cfg="{}"
[ -z "$cfg" ] && cfg="{}"
echo $(tmp=$(echo "$cfg" | jq ".$1" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
}
function get_feed_config_var()
{
local ppath=$(get_profile_path)
[ -f $ppath ] && cfg=$(cat $ppath) || cfg="{}"
[ -z "$cfg" ] && cfg="{}"
local packname=$1
local mode
if [ -z "$2" -o "$2" == "source" -o "$2" == "src" ]; then
mode="source"
elif [ "$2" == "hash" -o "$2" == "md5" ]; then
mode="hash"
elif [ "$2" == "branch" -o "$2" == "br" ]; then
mode="branch"
else
mode="source"
fi
[ -z "$packname" ] && echo "" || \
echo $(tmp=$(echo "$cfg" | jq ".feeds.$packname.$mode" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
}
function set_feed_config_var()
{
local ppath=$(get_profile_path)
[ -f $ppath ] && cfg=$(cat $ppath) || cfg="{}"
[ -z "$cfg" ] && cfg="{}"
local packname=$1
local src=$2
local hash=$3
local branch=$4
local opt=".id=0"
local orig="$opt"
if [ ! -z "$packname" ]; then
[ ! -z "$src" ] && opt="$opt | .feeds.$packname.source=\"$src\""
opt="$opt | .feeds.$packname.hash=\"$hash\""
[ ! -z "$branch" ] && opt="$opt | .feeds.$packname.branch=\"$branch\""
[ $verbose == true ] && lang "feeds name : $packname" "feeds 名 称 : $packname"
[ $verbose == true ] && lang "feeds source : $src" "feeds 数据源: $src"
[ $verbose == true ] && lang "feeds commit : $hash" "feeds 标 记 : $hash"
[ $verbose == true ] && lang "feeds branch : $branch" "feeds 分 支 : $branch"
[ "$orig" != "$opt" ] && ( \
tmp=$(echo "$cfg" | jq "$opt"); \
echo $tmp > $ppath; \
[ $verbose == true ] && echo $tmp ; \
lang "config change saved." "配置发生改变并储存" \
) || lang "no save." "配置未变更"
else
lang "no input feeds name." "请输入feeds名称"
fi
}
function del_feed_config()
{
local ppath=$(get_profile_path)
[ -f $ppath ] && cfg=$(cat $ppath) || cfg="{}"
[ -z "$cfg" ] && cfg="{}"
local packname=$1
if [ ! -z "$packname" ]; then
[ $verbose == true ] && lang "feeds name : $packname" "feeds 名 称 : $packname"
tmp=$(echo "$cfg" | jq "del(.feeds.$packname)")
echo $tmp > g
[ $verbose == true ] && echo $tmp
[ "$tmp" != "$cfg" ] && lang "config change saved." "配置发生改变并储存" || lang "no save." "配置未变更"
else
lang "no input feeds name." "请输入feeds名称"
fi
}
function load_hard_profile()
{
local ppath=$(get_profile_path)
[ -f $ppath ] && cfg=$(cat $ppath) || cfg="{}"
[ -z "$cfg" ] && cfg="{}"
op_hp=$(tmp=$(echo "$cfg" | jq ".profile_name" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_bp=$(tmp=$(echo "$cfg" | jq ".board_type" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_bn=$(tmp=$(echo "$cfg" | jq ".board_name" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_bt=$(tmp=$(echo "$cfg" | jq ".board_tag" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_pn=$(tmp=$(echo "$cfg" | jq ".project_name" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_pf=$(tmp=$(echo "$cfg" | jq ".platform" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_cn=$(tmp=$(echo "$cfg" | jq ".chip_name" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_tr=$(tmp=$(echo "$cfg" | jq ".tftp_root" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_tl=$(tmp=$(echo "$cfg" | jq ".tftp_link" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_bf=$(tmp=$(echo "$cfg" | jq ".bin_file" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_ud=$(tmp=$(echo "$cfg" | jq ".usb_dev" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_rr=$(tmp=$(echo "$cfg" | jq ".remote.root" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_lr=$(tmp=$(echo "$cfg" | jq ".local.root" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_pbc=$(tmp=$(echo "$cfg" | jq ".project.boardchip" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_pbt=$(tmp=$(echo "$cfg" | jq ".project.boardtype" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_pbn=$(tmp=$(echo "$cfg" | jq ".project.boardname" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_pbv=$(tmp=$(echo "$cfg" | jq ".project.boardver" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_pbd=$(tmp=$(echo "$cfg" | jq ".project.boarddate" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_uu=$(tmp=$(echo "$cfg" | jq ".upgrade.url" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_ua=$(tmp=$(echo "$cfg" | jq ".upgrade.useragent" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_rh=$(tmp=$(echo "$cfg" | jq ".release.hash" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_rb=$(tmp=$(echo "$cfg" | jq ".release.branch" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_bh=$(tmp=$(echo "$cfg" | jq ".beta.hash" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_bb=$(tmp=$(echo "$cfg" | jq ".beta.branch" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_ch=$(tmp=$(echo "$cfg" | jq ".current.hash" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_cb=$(tmp=$(echo "$cfg" | jq ".current.branch" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
op_lb=$(tmp=$(echo "$cfg" | jq ".last.branch" -r);[ "$tmp" != "null" ] && echo "$tmp" || echo "")
#$([ $(tmp=$(echo "$cfg" | jq ".usb_dev" -r);echo "$tmp") != "null" ] && echo $tmp || echo "")
}
function copy_config_var()
{
[ "$usb_dev" == "def" ] && usb_dev="-"
#[ "$remote_root" == "def" ] && remote_root="-"
#[ "$local_root" == "def" ] && local_root="-"
[ "$release_hash" == "def" ] && release_hash="-"
[ "$beta_hash" == "def" ] && beta_hash="-"
[ "$current_hash" == "def" ] && current_hash="-"
[ "$bin_file" == "def" ] && bin_file="-"
[ ! -z "$op_hp" -a "$hard_profile" == ".hardware" -a "$op_hp" != ".hardware" ] && hard_profile=$op_hp
[ ! -z "$op_bp" -a -z "$board_type" ] && board_type=$op_bp
[ ! -z "$op_bn" -a -z "$board_name" ] && board_name=$op_bn
[ ! -z "$op_bt" -a -z "$board_tag" ] && board_tag=$op_bt
[ ! -z "$op_pn" -a -z "$project_name" ] && project_name=$op_pn
[ ! -z "$op_pf" -a -z "$platform" ] && platform=$op_pf
[ ! -z "$op_cn" -a -z "$chip_name" ] && chip_name=$op_cn
[ ! -z "$op_tr" -a -z "$tftp_root" ] && tftp_root=$op_tr
[ ! -z "$op_tl" -a -z "$tftp_link" ] && tftp_link=$op_tl
[ ! -z "$op_bf" -a -z "$bin_file" -o "$bin_file" == "-" ] && bin_file=$op_bf
[ ! -z "$op_ud" -a -z "$usb_dev" -o "$usb_dev" == "-" ] && usb_dev=$op_ud
[ ! -z "$op_rr" -a -z "$remote_root" -o "$remote_root" == "-" ] && remote_root=$op_rr
[ ! -z "$op_lr" -a -z "$local_root" -o "$local_root" == "-" ] && local_root=$op_lr
[ ! -z "$op_pbc" -a -z "$project_boardchip" -o "$project_boardchip" == "-" ] && project_boardchip=$op_pbc
[ ! -z "$op_pbt" -a -z "$project_boardtype" -o "$project_boardtype" == "-" ] && project_boardtype=$op_pbt
[ ! -z "$op_pbn" -a -z "$project_boardname" -o "$project_boardname" == "-" ] && project_boardname=$op_pbn
[ ! -z "$op_pbv" -a -z "$project_boardver" -o "$project_boardver" == "-" ] && project_boardver=$op_pbv
[ ! -z "$op_pbd" -a -z "$project_boarddate" -o "$project_boarddate" == "-" ] && project_boarddate=$op_pbd
[ ! -z "$op_uu" -a -z "$upgrade_url" -o "$upgrade_url" == "-" ] && upgrade_url=$op_uu
[ ! -z "$op_ua" -a -z "$upgrade_user_agent" -o "$upgrade_user_agent" == "-" ] && upgrade_user_agent=$op_ua
[ ! -z "$op_rh" -a -z "$release_hash" -o "$release_hash" == "-" ] && release_hash=$op_rh
[ ! -z "$op_rb" -a -z "$release_branch" -o "$release_branch" == "-" ] && release_branch=$op_rb
[ ! -z "$op_bh" -a -z "$beta_hash" -o "$beta_hash" == "-" ] && beta_hash=$op_bh
[ ! -z "$op_bb" -a -z "$beta_branch" -o "$beta_branch" == "-" ] && beta_branch=$op_bb
[ ! -z "$op_ch" -a -z "$current_hash" -o "$current_hash" == "-" ] && current_hash=$op_ch
[ ! -z "$op_cb" -a -z "$current_branch" -o "$current_branch" == "-" ] && current_branch=$op_cb
[ ! -z "$op_lb" -a -z "$last_branch" -o "$last_branch" == "-" ] && last_branch=$op_lb
}
function save_hard_profile()
{
local opt=".id=0"
local orig="$opt"
local cfg=""
[ "$op_hp" != "$hard_profile" -a ! -z "$hard_profile" -a "$hard_profile" != ".hardware" ] && opt="$opt | .profile_name=
\"$hard_profile\""
[ "$op_bp" != "$board_type" -a ! -z "$board_type" ] && opt="$opt | .board_type=\"$board_type\""
[ "$op_bn" != "$board_name" -a ! -z "$board_name" ] && opt="$opt | .board_name=\"$board_name\""
[ "$op_bt" != "$board_tag" -a ! -z "$board_tag" ] && opt="$opt | .board_tag=\"$board_tag\""
[ "$op_pn" != "$project_name" -a ! -z "$project_name" ] && opt="$opt | .project_name=\"$project_name\""
[ "$op_pf" != "$platform" -a ! -z "$platform" ] && opt="$opt | .platform=\"$platform\""
[ "$op_cn" != "$chip_name" -a ! -z "$chip_name" ] && opt="$opt | .chip_name=\"$chip_name\""
[ "$op_tr" != "$tftp_root" -a ! -z "$tftp_root" ] && opt="$opt | .tftp_root=\"$tftp_root\""
[ "$op_tl" != "$tftp_link" -a ! -z "$tftp_link" ] && opt="$opt | .tftp_link=\"$tftp_link\""
[ "$op_bf" != "$bin_file" ] && opt="$opt | .bin_file=\"$bin_file\""
[ "$op_ud" != "$usb_dev" ] && opt="$opt | .usb_dev=\"$usb_dev\""
[ "$op_rr" != "$remote_root" ] && opt="$opt | .remote.root=\"$remote_root\""
[ "$op_lr" != "$local_root" ] && opt="$opt | .local.root=\"$local_root\""
[ "$op_pbc" != "$project_boardchip" ] && opt="$opt | .project.boardchip=\"$project_boardchip\""
[ "$op_pbt" != "$project_boardtype" ] && opt="$opt | .project.boardtype=\"$project_boardtype\""
[ "$op_pbn" != "$project_boardname" ] && opt="$opt | .project.boardname=\"$project_boardname\""
[ "$op_pbv" != "$project_boardver" ] && opt="$opt | .project.boardver=\"$project_boardver\""
[ "$op_pbd" != "$project_boarddate" ] && opt="$opt | .project.boarddate=\"$project_boarddate\""
[ "$op_uu" != "$upgrade_url" ] && opt="$opt | .upgrade.url=\"$upgrade_url\""
[ "$op_ua" != "$upgrade_user_agent" ] && opt="$opt | .upgrade.useragent=\"$upgrade_user_agent\""
[ "$op_rh" != "$release_hash" ] && opt="$opt | .release.hash=\"$release_hash\""
[ "$op_rb" != "$release_branch" ] && opt="$opt | .release.branch=\"$release_branch\""
[ "$op_bh" != "$beta_hash" ] && opt="$opt | .beta.hash=\"$beta_hash\""
[ "$op_bb" != "$beta_branch" ] && opt="$opt | .beta.branch=\"$beta_branch\""
[ "$op_ch" != "$current_hash" ] && opt="$opt | .current.hash=\"$current_hash\""
[ "$op_cb" != "$current_branch" ] && opt="$opt | .current.branch=\"$current_branch\""
[ "$op_lb" != "$last_branch" ] && opt="$opt | .last.branch=\"$last_branch\""
local ppath=$(get_profile_path)
[ -f $ppath ] && cfg=$(cat $ppath)
[ -z "$cfg" ] && cfg="{}"
[ "$orig" != "$opt" ] && ( \
tmp=$(echo "$cfg" | jq "$opt"); \
echo $tmp > $ppath; \
[ $verbose == true ] && echo $tmp ; \
lang "config change saved." "配置发生改变并储存" \
) || lang "no save." "配置未变更"
}
function show_config_var()
{
show i $(lang "show hardware profiles:" "显示硬件配置文件信息")
local ppath=$(get_profile_path)
local profile_name=$(get_config_var profile_name)
show l
if [ $verbose == false ]; then
echo " profile path :" $ppath
echo " profile_name :" $profile_name
echo " board_type :" $board_type
echo " board_name :" $board_name
echo " board_tag :" $board_tag
echo " project_name :" $project_name
echo " platform :" $platform
echo " chip_name :" $chip_name
echo " tftp_root :" $tftp_root
echo " tftp_link :" $tftp_link
echo " bin_file :" $bin_file
echo " usb_dev :" $usb_dev
echo " remote_root :" $remote_root
echo " local_root :" $local_root
echo " project.boardchip :" $project_boardchip
echo " project.boardtype :" $project_boardtype
echo " project.boardname :" $project_boardname
echo " project.boardver :" $project_boardver
echo " project.boarddate :" $project_boarddate
echo " upgrade.url :" $upgrade_url
echo " upgrade.useragent :" $upgrade_user_agent
echo " release.hash :" $release_hash
echo " release.branch :" $release_branch
echo " beta.hash :" $beta_hash
echo " beta.branch :" $beta_branch
echo " current.hash :" $current_hash
echo " current.branch :" $current_branch
echo " last.branch :" $last_branch
else
echo " profile path :" $ppath
echo " profile_name :" $profile_name "($op_hp)"
echo " board_type :" $board_type "($op_bp)"
echo " board_name :" $board_name "($op_bn)"
echo " board_tag :" $board_tag "($op_bt)"
echo " project_name :" $project_name "($op_pn)"
echo " platform :" $platform "($op_pf)"
echo " chip_name :" $chip_name "($op_cn)"
echo " tftp_root :" $tftp_root "($op_tr)"
echo " tftp_link :" $tftp_link "($op_tl)"
echo " bin_file :" $bin_file "($op_bf)"
echo " usb_dev :" $usb_dev "($op_ud)"
echo " remote_root :" $remote_root "($op_rr)"
echo " local_root :" $local_root "($op_lr)"
echo " project.boardchip :" $project_boardchip "($op_pbc)"
echo " project.boardtype :" $project_boardtype "($op_pbt)"
echo " project.boardname :" $project_boardname "($op_pbn)"
echo " project.boardver :" $project_boardver "($op_pbv)"
echo " project.boarddate :" $project_boarddate "($op_pbd)"
echo " upgrade.url :" $upgrade_url "($op_uu)"
echo " upgrade.useragent :" $upgrade_user_agent "($op_ua)"
echo " release.hash :" $release_hash "($op_rh)"
echo " release.branch :" $release_branch "($op_rb)"
echo " beta.hash :" $beta_hash "($op_bh)"
echo " beta.branch :" $beta_branch "($op_bb)"
echo " current.hash :" $current_hash "($op_ch)"
echo " current.branch :" $current_branch "($op_cb)"
echo " last.branch :" $last_branch "($op_lb)"
fi
show l
}
function action_list_profiles()
{
show i $(lang "list hardware profiles:" "列表所有硬件配置文件名称")
ls "$op_root/profiles/" | grep -v "~" | sort | awk -F"." '!a[$1]++{print " "$1}'
doaction=true
}
function action_use_profile()
{
show i $(lang "link hardware profiles to .hardware:" "设置硬件配置文件为编译默认选项")
[ -z "$use_profile" ] && use_profile="default"
if [ ! -z "$use_profile" -a -f "$op_hp_dir/$use_profile.json" ]; then
show s $(lang "'$use_profile' hardware profiles => .hardware" "'$use_profile' 硬件配置文件链接到 .hardware")
[ -f "$op_root/.hardware" ] && rm -f "$op_root/.hardware"
ln -s "$op_hp_dir/$use_profile.json" "$op_root/.hardware"
else
show s $(lang "'$use_profile' hardware profiles not exists!" "'$use_profile'硬件配置文件不存在")
fi
doaction=true
}
function action_remove_profile()
{
show i $(lang "remove select hardware profile:" "删除一个硬件配置文件")
if [ -z "$remove_profile" ]; then
show s $(lang "please input hardware profile name" "请输入要删除的硬件配置文件名")
exit 0
fi
if [ -f "$op_hp_dir/$remove_profile.json" ]; then
read -p $(lang " are you remove '$remove_profile' hardware profile(Y/n):" " 确认删除'$remove_profile'硬件配置文件(Y/n):") request
if [ "$request" == "y" -o "$request" == "Y" -o "$request" == "yes" ]; then
show s $(lang "remove '$remove_profile' hardware profile success" "成功删除'$remove_profile'硬件配置文件")
rm -f "$op_hp_dir/$remove_profile.json"
if [ -e "$op_root/.hardware" ]; then
rm -f "$op_root/.hardware"
show s $(lang "remove '.hardware' profile success" "成功删除'.hardware'硬件配置文件软链")
fi
else
show s $(lang "remove '$remove_profile' hardware profile failed" "删除'$remove_profile'硬件配置文件失败")
fi
fi
doaction=true
}
function action_new_profile()
{
show i $(lang "add new hardware profile:" "产生新的硬件配置文件")
action_set_default_config
[ ! -z "$add_profile" ] && hard_profile=$add_profile
#echo $hard_profile
show_config_var
[ $only_show == true ] && echo $(lang "only show changed. don't write config" "仅显示变更,不写配置文件") || save_hard_profile
doaction=true
}
function action_set_default_config()
{
show i $(lang "list hardware profiles:" "设置默认配置")
#hard_profile="default"
board_type="wrtoy"
board_name="wrtoy"
board_tag="WRTOY"
project_name="mtall"
platform="ramips"
chip_name="mt7620"
tftp_root="$op_tl_dir"
tftp_link="wrtbin"
usb_dev=""
remote_root=""
local_root=""
project_boardchip=""
project_boardtype=""
project_boardname=""
project_boardver=""
project_boarddate=""
upgrade_url=""
upgrade_user_agent=""
release_hash=""
release_branch=""
beta_hash=""
beta_branch=""
current_hash=""
current_branch=""
last_branch=""
}
function action_list_feeds()
{
show i $(lang "show project's feeds config:" "显示项目feeds配置信息")
local ppath=$(get_profile_path)
[ -f $ppath ] && cfg=$(cat $ppath) || cfg="{}"
[ -z "$cfg" ] && cfg="{}"
local flen=$(echo "$cfg" | jq ".feeds | length" -r)
local feed_name
local feed_src
local feed_hash
local feed_branch
show l
for((i=0;i<$flen;i++))
do
feed_name=$(echo "$cfg" | jq ".feeds | keys | .[$i]" -r)
feed_src=$(echo "$cfg" | jq ".feeds.$feed_name.source" -r)
feed_hash=$(echo "$cfg" | jq ".feeds.$feed_name.hash" -r)
feed_branch=$(echo "$cfg" | jq ".feeds.$feed_name.branch" -r)
[ "$feed_hash" == "null" ] && feed_hash=""
[ "$feed_branch" == "null" ] && feed_branch=""
echo " $i.[$feed_name] $feed_src $feed_branch $feed_hash "
show l
done
}
function action_add_feeds()
{
show i $(lang "add feeds new config:" "增加新feeds配置信息")
[ -z "$feeds_source" ] && lang "no feeds source" "没有feeds数据源"
[ ! -z "$add_feeds" ] && set_feed_config_var "$add_feeds" "$feeds_source" "$feeds_hash" "$feeds_branch"
}
function action_edit_feeds()
{
show i $(lang "edit feeds config:" "编辑feeds配置信息")
[ ! -z "$edit_feeds" ] && set_feed_config_var "$edit_feeds" "$feeds_source" "$feeds_hash" "$feeds_branch"
}
function action_del_feeds()
{
show i $(lang "delete feeds config:" "删除feeds配置信息")
[ ! -z "$delete_feeds" ] && del_feed_config "$delete_feeds"
}
function action_config()
{
[ $doaction == true ] && exit 0
load_hard_profile
copy_config_var
show_config_var
[ $only_show == true ] && echo $(lang "only show changed. don't write config" "仅显示变更,不写配置文件") || save_hard_profile
[ $list_feeds == true ] && action_list_feeds
[ ! -z "$add_feeds" ] && (action_add_feeds; action_list_feeds)
[ ! -z "$edit_feeds" ] && (action_edit_feeds; action_list_feeds)
[ ! -z "$delete_feeds" ] && (action_del_feeds; action_list_feeds)
exit 0
}
function show_cfg_var()
{
local tag
[ ! -z "$2" -a $verbose == true ] && tag="$2="
[ -z "$1" -o "$1" == " " ] && echo "$tag$3" || echo "$tag$1"
}
function action_get_cfg_var()
{
[ ! -f "./.hardware" ] && exit 0
load_hard_profile
[ -z "$get_variable" -o "$get_variable" == "-" ] && get_variable="all"
[ "$get_variable" == "bp" -o \
"$get_variable" == "boardtype" -o \
"$get_variable" == "board_type" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_bp" "board_type"
[ "$get_variable" == "bn" -o \
"$get_variable" == "boardname" -o \
"$get_variable" == "board_name" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_bn" "board_name"
[ "$get_variable" == "bt" -o \
"$get_variable" == "boardtag" -o \
"$get_variable" == "board_tag" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_bt" "board_tag"
[ "$get_variable" == "pn" -o \
"$get_variable" == "projectname" -o \
"$get_variable" == "project_name" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_pn" "project_name"
[ "$get_variable" == "pf" -o \
"$get_variable" == "platform" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_pf" "platform"
[ "$get_variable" == "cn" -o \
"$get_variable" == "chipname" -o \
"$get_variable" == "chip_name" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_cn" "chip_name"
[ "$get_variable" == "tr" -o \
"$get_variable" == "tftproot" -o \
"$get_variable" == "tftp_root" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_tr" "tftp_root"
[ "$get_variable" == "tl" -o \
"$get_variable" == "tftplink" -o \
"$get_variable" == "tftp_link" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_tl" "tftp_link"
[ "$get_variable" == "ud" -o \
"$get_variable" == "usbdev" -o \
"$get_variable" == "usb_dev" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_ud" "usb_dev"
[ "$get_variable" == "rr" -o \
"$get_variable" == "remoteroot" -o \
"$get_variable" == "remote_root" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_rr" "remote_root"
[ "$get_variable" == "lr" -o \
"$get_variable" == "localroot" -o \
"$get_variable" == "local_root" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_lr" "local_root"
[ "$get_variable" == "pbc" -o \
"$get_variable" == "projectboardchip" -o \
"$get_variable" == "project.boardchip" -o \
"$get_variable" == "project_boardchip" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_pbc" "project_boardchip"
[ "$get_variable" == "pbt" -o \
"$get_variable" == "projectboardtype" -o \
"$get_variable" == "project.boardtype" -o \
"$get_variable" == "project_boardtype" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_pbt" "project_boardtype"
[ "$get_variable" == "pbn" -o \
"$get_variable" == "projectboardname" -o \
"$get_variable" == "project.boardname" -o \
"$get_variable" == "project_boardname" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_pbn" "project_boardname"
[ "$get_variable" == "pbv" -o \
"$get_variable" == "projectboardver" -o \
"$get_variable" == "project.boardver" -o \
"$get_variable" == "project_boardver" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_pbv" "project_boardver"
[ "$get_variable" == "pbd" -o \
"$get_variable" == "projectboarddate" -o \
"$get_variable" == "project.boarddate" -o \
"$get_variable" == "project_boarddate" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_pbd" "project_boarddate"
[ "$get_variable" == "uu" -o \
"$get_variable" == "upgradeurl" -o \
"$get_variable" == "upgrade.url" -o \
"$get_variable" == "upgrade_url" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_uu" "upgrade_url"
[ "$get_variable" == "ua" -o \
"$get_variable" == "upgradeuseragent" -o \
"$get_variable" == "upgrade.useragent" -o \
"$get_variable" == "upgrade_useragent" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_ua" "upgrade_useragent"
[ "$get_variable" == "rh" -o \
"$get_variable" == "releasehash" -o \
"$get_variable" == "release_hash" -o \
"$get_variable" == "release.hash" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_rh" "release_hash"
[ "$get_variable" == "rb" -o \
"$get_variable" == "releasebranch" -o \
"$get_variable" == "release_branch" -o \
"$get_variable" == "release.branch" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_rb" "release_branch" "master"
[ "$get_variable" == "bh" -o \
"$get_variable" == "betahash" -o \
"$get_variable" == "beta_hash" -o \
"$get_variable" == "beta.hash" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_bh" "beta_hash"
[ "$get_variable" == "bb" -o \
"$get_variable" == "betabranch" -o \
"$get_variable" == "beta_branch" -o \
"$get_variable" == "beta.branch" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_bb" "beta_branch" "master"
[ "$get_variable" == "ch" -o \
"$get_variable" == "currenthash" -o \
"$get_variable" == "current_hash" -o \
"$get_variable" == "current.hash" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_ch" "current_hash"
[ "$get_variable" == "cb" -o \
"$get_variable" == "currentbranch" -o \
"$get_variable" == "current_branch" -o \
"$get_variable" == "current.branch" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_cb" "current_branch" "master"
[ "$get_variable" == "lb" -o \
"$get_variable" == "lastbranch" -o \
"$get_variable" == "last_branch" -o \
"$get_variable" == "last.branch" -o \
"$get_variable" == "all" ] && \
show_cfg_var "$op_lb" "last_branch" "master"
if [ "$get_variable" == "bf" -o \
"$get_variable" == "binfile" -o \
"$get_variable" == "bin_file" -o \
"$get_variable" == "all" ]; then
local bf=$(show_cfg_var "$op_bf")
if [ ! -z "$bf" -a "$bf" != "-" ]; then
echo "$bf"
else
if [ "$op_pf" == "ramips" ]; then
show_cfg_var "openwrt-$op_pf-$op_cn-$op_bn-squashfs-sysupgrade.bin" "bin_file"
elif [ "$op_pf" == "x86" ]; then
#show_cfg_var "openwrt-$op_pf-$op_bn-combined-ext4.img" "bin_file"
show_cfg_var "openwrt-$op_pf-$op_bn-combined-squashfs.img" "bin_file"
elif [ "$op_pf" == "rpi" ]; then
show_cfg_var "openwrt-brcm2708-sdcard-vfat-ext4.img" "bin_file"
fi
fi
fi
exit 0
}
doaction=false
op_root=$(get_wrtoy_path)
op_wrtoy_dir=$(get_wrtoy_path ..)
op_hp_dir=$(get_wrtoy_path profiles)
op_tl_dir=$(get_wrtoy_path ../tftproot)
op_dir=$(get_wrtoy_path ../openwrt)
#======================================================
help_hard_profile=$(lang \
"set hardware profile name" \
"设置硬件配置名称(如果为空,则存在.hardware软链默认用软链,否则用default)")
addOption -hp --hardware-profile \
dest=hard_profile \
help="$help_hard_profile"
#======================================================
help_board_type=$(lang \
"set board type" \
"设置硬件主板类型")
addOption -bp --board-type \
dest=board_type \
help="$help_board_type"
#======================================================
help_board_name=$(lang \
"set board name" \
"设置硬件主板名称")
addOption -bn --board-name \
dest=board_name \
help="$help_board_name"
#======================================================
help_board_tag=$(lang \
"set board tag" \
"设置硬件标识(和DTS一致)")
addOption -bt --board-tag \
dest=board_tag \
help="$help_board_tag"
#======================================================
help_project_name=$(lang \
"set project name" \
"设置项目名称")
addOption -pn --project-name \
dest=project_name \
help="$help_project_name"
#======================================================
help_platform=$(lang \
"set platform name" \
"设置平台信息")
addOption -pf --platform \
dest=platform \
help="$help_platform"
#======================================================
help_chip_name=$(lang \
"set chip name" \
"设置主控芯片名称")
addOption -cn --chip-name \
dest=chip_name \
help="$help_chip_name"
#======================================================
help_tftp_root=$(lang \
"set tftp server root directory" \
"设置tftp服务根目录")
addOption -tr --tftp-root \
dest=tftp_root \
help="$help_tftp_root"
#======================================================
help_tftp_link=$(lang \
"set openwrt firmware short link name form tftp server root directory" \
"设置产生的openwrt固件在tftp中的软链名称")
addOption -tl --tftp-link \
dest=tftp_link \
help="$help_tftp_link"
#======================================================
help_usb_dev=$(lang \
"set usb device path" \
"设置usb设备文件路径")
addOption -ud --usb-dev \
default=- dest=usb_dev \
help="$help_usb_dev"
#======================================================
help_remote_root=$(lang \
"set firmware upgrade remote root directory" \
"设置固件远程更新上传的服务器路径")
addOption -rr --remote-root \
default=- dest=remote_root \
help="$help_remote_root"
#======================================================
help_local_root=$(lang \
"set firmware upgrade local root directory" \
"设置固件远程更新上传的服务器路径的本地映射目录")
addOption -lr --local-root \
default=- dest=local_root \
help="$help_local_root"
#======================================================
help_project_boardchip=$(lang \
"set project board chip" \
"设置项目所用开发板的芯片方案")
addOption -pbc --project-boardchip \
default=- dest=project_boardchip \
help="$help_project_boardchip"
#======================================================
help_project_boardtype=$(lang \
"set project board type" \
"设置项目所用开发板的编号")
addOption -pbt --project-boardtype \
default=- dest=project_boardtype \
help="help_project_boardtype"
#======================================================
help_project_boardname=$(lang \
"set project board name" \
"设置项目所用开发板的别名")
addOption -pbn --project-boardname \
default=- dest=project_boardname \
help="help_project_boardname"
#======================================================
help_project_boardver=$(lang \
"set project board version" \
"设置项目所用开发板的版本号")
addOption -pbv --project-boardver \
default=- dest=project_boardver \
help="$help_project_boardver"
#======================================================
help_project_boarddate=$(lang \
"set project board date" \
"设置项目所用开发板的定版时间")
addOption -pbd --project-boarddate \
default=- dest=project_boarddate \
help="$help_project_boarddate"
#======================================================
help_upgrade_url=$(lang \
"set openwrt firmware upgrade url" \
"设置openwrt固件远程升级url")
addOption -uu --upgrade-url \
default=- dest=upgrade_url \
help="$help_upgrade_url"
#======================================================
help_upgrade_user_agent=$(lang \
"set openwrt firmware upgrade user-agent" \
"设置openwrt固件远程升级UA")
addOption -ua --upgrade-useragent \
default=- dest=upgrade_user_agent \
help="$help_upgrade_user_agent"
#======================================================
help_release_hash=$(lang \
"set openwrt release build hash" \
"设置openwrt发布版构建hash")
addOption -rh --release-hash \
default=- dest=release_hash \
help="$help_release_hash"
#======================================================
help_release_branch=$(lang \
"set openwrt release build branch" \
"设置openwrt发布版构建branch")
addOption -rb --release-branch \
default=- dest=release_branch \
help="$help_release_branch"
#======================================================
help_beta_hash=$(lang \
"set openwrt beta build hash" \
"设置openwrt测试版构建hash")
addOption -bh --beta-hash \
default=- dest=beta_hash \
help="$help_beta_hash"
#======================================================
help_beta_branch=$(lang \
"set openwrt beta build branch" \
"设置openwrt测试版构建branch")
addOption -bb --beta-branch \
default=- dest=beta_branch \
help="$help_beta_branch"
#======================================================
help_current_hash=$(lang \
"set openwrt current/work build hash" \
"设置openwrt当前/工作版本构建hash")
addOption -ch --current-hash \
default=- dest=current_hash \
help="$help_current_hash"
#======================================================
help_current_branch=$(lang \
"set openwrt current/work build branch" \
"设置openwrt当前/工作版本构建branch")
addOption -cb --current-branch \
default=- dest=current_branch \
help="$help_current_branch"
#======================================================
help_last_branch=$(lang \
"set openwrt current/work build last branch" \
"设置openwrt当前/工作版本构建branch")
addOption -lb --last-branch \
default=- dest=last_branch \
help="$help_last_branch"
#======================================================
help_bin_file=$(lang \
"set copy openwrt's build image file to tftproot" \
"设置向tftp复制的openwrt生成的镜像文件")
addOption -bf --bin-file \
default=- dest=bin_file \
help="$help_bin_file"
#======================================================
help_list_feeds=$(lang \
"list all feeds" \
"列表所有的feeds")
addOption -lf --list-feeds \
flagTrue dest=list_feeds \
help="$help_list_feeds"
#======================================================
help_add_feeds=$(lang \
"add new feeds" \
"增加一个feeds")
addOption -af --add-feeds \
dest=add_feeds \
help="$help_add_feeds"
#======================================================
help_edit_feeds=$(lang \
"edit select feeds" \
"编辑一个feeds")
addOption -ef --edit-feeds \
dest=edit_feeds \
help="$help_edit_feeds"
#======================================================
help_delete_feeds=$(lang \
"delete select feeds" \
"删除一个feeds")
addOption -df --delete-feeds \
dest=delete_feeds \
help="$help_delete_feeds"
#======================================================
help_feeds_source=$(lang \
"set feeds source" \
"设置feeds的源")
addOption -fs --feeds-source \
dest=feeds_source \
help="$help_feeds_source"
#======================================================
help_feeds_hash=$(lang \
"set feeds git commit" \
"设置feeds的库git版本")
addOption -fh --feeds-hash \
dest=feeds_hash \
help="$help_feeds_hash"
#======================================================
help_feeds_branch=$(lang \
"set feeds git branch" \
"设置feeds的库git版本branch分支")
addOption -fb --feeds-branch \
dest=feeds_branch \
help="$help_feeds_branch"
#======================================================
help_get_var=$(lang \
"get .hardwave profile env variable" \
"获取当前配置(.hardware)相关变量")
addOption -gv --get-var \
action=action_get_cfg_var dest=get_variable \
help="$help_get_var"
#======================================================
help_add_profile=$(lang \
"add new hardware profile (use default config)" \
"加入新的硬件配置文件(用默认配置)")
addOption -a --add-profile \
action=action_new_profile dest=add_profile \
help="$help_add_profile"
#======================================================
help_remove_profile=$(lang \
"remove select hardware profile" \
"删除一个硬件配置文件")
addOption -r --remove-profile \
action=action_remove_profile dest=remove_profile \
help="$help_remove_profile"
#======================================================
help_list_profiles=$(lang \
"list all hardware profiles" \
"列表所有硬件配置文件")
addOption -l --list-profiles \
action=action_list_profiles dest=list_profiles \
help="$help_list_profiles"
#======================================================
help_use_profile=$(lang \
"link hardware profiles to .hardware" \
"设置硬件配置文件为编译默认选项(.hardware)")
addOption -u --use-profile \
action=action_use_profile dest=use_profile \
help="$help_use_profile"
#======================================================
help_only_show=$(lang \
"only show change don't write" \
"仅显示数据变更不写入文件")
addOption -s --only-show \
flagTrue dest=only_show \
help="$help_only_show"
#======================================================
help_verbose=$(lang \
"show verbose" \
"显示更多调试信息")
addOption -v --verbose \
flagTrue dest=verbose \
help="$help_verbose"
#======================================================
parseOptions "$@"
action_config
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化