- echo 'echo "========================================================"' > postinst
- echo 'echo "retrieving texlive..."' >> postinst
- echo 'echo "you can start this manually by calling termux-install-tl"' >> postinst
- echo 'echo "========================================================"' >> postinst
- echo "termux-install-tl" >> postinst
+ # Clean texlive's folder if needed (run on upgrade)
+ echo "#!$TERMUX_PREFIX/bin/sh" > preinst
+ echo "if [ ! -f $TERMUX_PREFIX/opt/texlive/2016/install-tl -a ! -f $TERMUX_PREFIX/opt/texlive/2017/install-tl ]; then exit 0; else echo 'Removing residual files from old version of TeX Live for Termux'; fi" >> preinst
+ echo "rm -rf $TERMUX_PREFIX/etc/profile.d/texlive.sh" >> preinst
+ echo "rm -rf $TERMUX_PREFIX/opt/texlive/2016" >> preinst
+ # Let's not delete the previous texmf-dist so that people who have installed a full distribution won't need to download everything again
+ echo "rm -rf $TERMUX_PREFIX/opt/texlive/2017/!(texmf-dist)" >> preinst
+ echo "exit 0" >> preinst
+ chmod 0755 preinst
+
+ echo "#!$TERMUX_PREFIX/bin/sh" > postinst
+ echo "mkdir -p $TL_ROOT/{tlpkg/{backups,tlpobj},texmf-var/{web2c,tex/generic/config}}" >> postinst
+ echo "export PATH=\$PATH:$TL_BINDIR" >> postinst
+ echo "echo Updating tlmgr" >> postinst
+ echo "tlmgr update --self" >> postinst
+ echo "echo Generating language files and setting up symlinks" >> postinst
+ echo "tlmgr -q generate language" >> postinst
+ echo "mktexlsr $TL_ROOT/texmf-var" >> postinst
+ echo "texlinks" >> postinst
+ echo "echo ''" >> postinst
+ echo "echo Welcome to TeX Live!" >> postinst
+ echo "echo ''" >> postinst
+ echo "echo 'TeX Live is a joint project of the TeX user groups around the world;'" >> postinst
+ echo "echo 'please consider supporting it by joining the group best for you.'" >> postinst
+ echo "echo 'The list of groups is available on the web at http://tug.org/usergroups.html.'" >> postinst
+ echo "echo ''" >> postinst
+ echo "echo 'Please run \"source $PREFIX/etc/profile.d/texlive.sh\" to add texlive'\''s binaries to your current shell'\''s PATH.'" >> postinst