66#
77# ./install.sh mpy
88
9-
9+ PKGNAME= " Arduino Runtime for MicroPython "
1010PKGDIR=" arduino"
1111SRCDIR=$PKGDIR
1212LIBDIR=" lib"
@@ -59,7 +59,7 @@ function delete_file {
5959 fi
6060}
6161
62- echo " Installing Arduino Runtime for MicroPython "
62+ echo " Installing $PKGNAME "
6363
6464# If directories do not exist, create them
6565if ! directory_exists " /${LIBDIR} " ; then
@@ -86,6 +86,30 @@ for filename in $SRCDIR/*; do
8686 source_extension=" ${f_name##* .} "
8787 destination_extension=$source_extension
8888
89+ if [[ -d $filename && " $f_name " == " examples" ]]; then
90+ if ! directory_exists " /${LIBDIR} /${PKGDIR} /examples" ; then
91+ echo " Creating $LIBDIR /$PKGDIR /examples on board"
92+ mpremote mkdir " /${LIBDIR} /${PKGDIR} /examples"
93+ fi
94+
95+ for example_file in $filename /* ; do
96+ example_f_name=` basename $example_file `
97+ example_source_extension=" ${example_f_name##* .} "
98+ example_destination_extension=$example_source_extension
99+
100+ if [[ $existing_files == * " ${example_f_name% .* } .$example_source_extension " * ]]; then
101+ delete_file " :/${LIBDIR} /$PKGDIR /examples/${example_f_name% .* } .$example_source_extension "
102+ fi
103+
104+ if [ " $example_source_extension " = " py" ] && [[ $existing_files == * " ${example_f_name% .* } .mpy" * ]]; then
105+ delete_file " :/${LIBDIR} /$PKGDIR /examples/${example_f_name% .* } .mpy"
106+ fi
107+
108+ copy_file $filename /${example_f_name% .* } .$example_destination_extension " :/${LIBDIR} /$PKGDIR /examples/${example_f_name% .* } .$example_destination_extension "
109+ done
110+ continue
111+ fi
112+
89113 if [[ " $ext " == " mpy" && " $source_extension " == " py" ]]; then
90114 echo " Compiling $SRCDIR /$f_name to $SRCDIR /${f_name% .* } .$ext "
91115 mpy-cross " $SRCDIR /$f_name "
@@ -106,7 +130,7 @@ for filename in $SRCDIR/*; do
106130 copy_file $SRCDIR /${f_name% .* } .$destination_extension " :/${LIBDIR} /$PKGDIR /${f_name% .* } .$destination_extension "
107131done
108132
109- if [ " $ext " = " mpy" ]; then
133+ if [ " $ext " == " mpy" ]; then
110134 echo " cleaning up mpy files"
111135 rm $SRCDIR /* .mpy
112136fi
0 commit comments