ysyx-workbench/init.sh

77 lines
1.9 KiB
Bash
Raw Normal View History

2022-02-21 04:22:27 +00:00
#!/bin/bash
2022-03-08 02:50:24 +00:00
# usage: addenv env_name path
function addenv() {
sed -i -e "/^export $1=.*/d" ~/.bashrc
2023-04-04 07:48:29 +00:00
echo "export $1=`readlink -f $2`" >> ~/.bashrc
2022-03-08 02:50:24 +00:00
echo "By default this script will add environment variables into ~/.bashrc."
echo "After that, please run 'source ~/.bashrc' to let these variables take effect."
echo "If you use shell other than bash, please add these environment variables manually."
}
2022-02-21 04:22:27 +00:00
# usage: init repo branch directory trace [env]
# trace = true|false
function init() {
if [ -d $3 ]; then
echo "$3 is already initialized, skipping..."
return
fi
while [ ! -d $3 ]; do
git clone -b $2 git@github.com:$1.git $3
done
log="$1 `cd $3 && git log --oneline --no-abbrev-commit -n1`"$'\n'
if [ $4 == "true" ] ; then
rm -rf $3/.git
git add -A $3
git commit -am "$1 $2 initialized"$'\n\n'"$log"
else
sed -i -e "/^\/$3/d" .gitignore
echo "/$3" >> .gitignore
git add -A .gitignore
git commit --no-verify --allow-empty -am "$1 $2 initialized without tracing"$'\n\n'"$log"
fi
if [ $5 ] ; then
2022-03-08 02:50:24 +00:00
addenv $5 $3
2022-02-21 04:22:27 +00:00
fi
}
case $1 in
nemu)
init NJU-ProjectN/nemu ysyx2204 nemu true NEMU_HOME
;;
abstract-machine)
init NJU-ProjectN/abstract-machine ysyx2204 abstract-machine true AM_HOME
init NJU-ProjectN/fceux-am ics2021 fceux-am false
;;
am-kernels)
init NJU-ProjectN/am-kernels ics2021 am-kernels false
;;
nanos-lite)
init NJU-ProjectN/nanos-lite ics2021 nanos-lite true
;;
navy-apps)
init NJU-ProjectN/navy-apps ics2021 navy-apps true NAVY_HOME
;;
nvboard)
init NJU-ProjectN/nvboard master nvboard false NVBOARD_HOME
;;
npc-chisel)
if [ -d npc/playground ]; then
echo "chisel repo is already initialized, skipping..."
else
rm -rf npc
init OpenXiangShan/chisel-playground ysyx2204 npc true NPC_HOME
fi
;;
npc)
2022-03-08 02:50:24 +00:00
addenv NPC_HOME npc
2022-02-21 04:22:27 +00:00
;;
*)
echo "Invalid input..."
exit
;;
esac