mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
Improve APE install scripts and add uninstaller
See #350 thanks @tkchia
This commit is contained in:
parent
331fdd1d29
commit
68ca49bfdd
4 changed files with 149 additions and 68 deletions
44
README.md
44
README.md
|
@ -47,22 +47,21 @@ that maps your program into memory without needing to copy it. It's
|
||||||
possible to install the APE loader systemwide as follows.
|
possible to install the APE loader systemwide as follows.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# (1) linux systems that want binfmt_misc
|
# System-Wide APE Install
|
||||||
|
# for Linux, Darwin, and BSDs
|
||||||
|
# 1. Copies APE Loader to /usr/bin/ape
|
||||||
|
# 2. Registers w/ binfmt_misc too if Linux
|
||||||
ape/apeinstall.sh
|
ape/apeinstall.sh
|
||||||
|
|
||||||
# (2) for linux/freebsd/netbsd/openbsd systems
|
# System-Wide APE Uninstall
|
||||||
cp build/bootstrap/ape.elf /usr/bin/ape
|
# for Linux, Darwin, and BSDs
|
||||||
|
ape/apeuninstall.sh
|
||||||
# (3) for mac os x systems
|
|
||||||
cp build/bootstrap/ape.macho /usr/bin/ape
|
|
||||||
```
|
```
|
||||||
|
|
||||||
If you followed steps (2) and (3) then there's going to be a slight
|
It's also possible to convert APE binaries into the system-local format
|
||||||
constant-time startup latency each time you run an APE binary. Your
|
by using the `--assimilate` flag. Plesae note that if binfmt_misc is in
|
||||||
system might also prevent your APE program from being installed to a
|
play, you'll need to unregister it temporarily before doing this, since
|
||||||
system directory as a setuid binary or a script interpreter. To solve
|
the assimilate feature is part of the shell script header.
|
||||||
that, you can use the following flag to turn your binary into the
|
|
||||||
platform local format (ELF or Mach-O):
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ file hello.com
|
$ file hello.com
|
||||||
|
@ -72,18 +71,27 @@ $ file hello.com
|
||||||
hello.com: ELF 64-bit LSB executable
|
hello.com: ELF 64-bit LSB executable
|
||||||
```
|
```
|
||||||
|
|
||||||
There's also some other useful flags that get baked into your binary by
|
Now that you're up and running with Cosmopolitan Libc and APE, here's
|
||||||
default:
|
some of the most important troubleshooting tools APE offers that you
|
||||||
|
should know, in case you encounter any issues:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./hello.com --strace # log system calls to stderr
|
./hello.com --strace # log system calls to stderr
|
||||||
./hello.com --ftrace # log function calls to stderr
|
./hello.com --ftrace # log function calls to stderr
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want your `hello.com` program to be much tinier, more on the
|
Do you love tiny binaries? If so, you may not be happy with Cosmo adding
|
||||||
order of 16kb rather than 60kb, then all you have to do is use
|
heavyweight features like tracing to your binaries by default. In that
|
||||||
<https://justine.lol/cosmopolitan/cosmopolitan-tiny.zip> instead. See
|
case, you may want to consider using our build system:
|
||||||
<https://justine.lol/cosmopolitan/download.html>.
|
|
||||||
|
```sh
|
||||||
|
make -j8 MODE=tiny
|
||||||
|
```
|
||||||
|
|
||||||
|
Which will cause programs such as `hello.com` and `life.com` to shrink
|
||||||
|
from 60kb in size to about 16kb. There's also a prebuilt amalgamation
|
||||||
|
online <https://justine.lol/cosmopolitan/cosmopolitan-tiny.zip> hosted
|
||||||
|
on our download page <https://justine.lol/cosmopolitan/download.html>.
|
||||||
|
|
||||||
### MacOS
|
### MacOS
|
||||||
|
|
||||||
|
|
|
@ -1,39 +1,76 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
if ! [ x"$(uname -s)" = xLinux ]; then
|
if [ $UID -eq 0 ]; then
|
||||||
echo this script is intended for linux binfmt_misc >&2
|
SUDO=
|
||||||
echo freebsd/netbsd/openbsd users can use release binary >&2
|
else
|
||||||
exit 1
|
SUDO=sudo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Actually Portable Executable (APE) Installer" >&2
|
||||||
|
echo "Author: Justine Tunney <jtunney@gmail.com>" >&2
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# INSTALL APE LOADER SYSTEMWIDE
|
||||||
|
|
||||||
if [ -f o/depend ]; then
|
if [ -f o/depend ]; then
|
||||||
# mkdeps.com build was successfully run so assume we can build
|
# mkdeps.com build was successfully run so assume we can build
|
||||||
echo >&2
|
echo >&2
|
||||||
echo running: make -j8 o//ape/ape.elf >&2
|
echo "recompiling ape loader" >&2
|
||||||
make -j8 o//ape/ape.elf || exit
|
echo "running: make -j8 o//ape" >&2
|
||||||
echo done >&2
|
make -j8 o//ape || exit
|
||||||
else
|
echo "done" >&2
|
||||||
# no evidence we can build, use prebuilt one
|
elif [ -d build/bootstrap ]; then
|
||||||
|
# if make isn't being used then it's unlikely the user changed the sources
|
||||||
|
# in that case the prebuilt binaries should be completely up-to-date
|
||||||
|
echo "using prebuilt ape loader from cosmo repo" >&2
|
||||||
mkdir -p o//ape || exit
|
mkdir -p o//ape || exit
|
||||||
cp -af build/bootstrap/ape.elf o//ape/ape.elf
|
cp -af build/bootstrap/ape.elf o//ape/ape.elf || exit
|
||||||
|
cp -af build/bootstrap/ape.macho o//ape/ape.macho || exit
|
||||||
|
else
|
||||||
|
echo "no cosmopolitan libc repository here" >&2
|
||||||
|
echo "fetching ape loader from justine.lol" >&2
|
||||||
|
mkdir -p o//ape || exit
|
||||||
|
if command -v wget >/dev/null 2>&1; then
|
||||||
|
wget -qO o//ape/ape.elf https://justine.lol/ape.elf || exit
|
||||||
|
wget -qO o//ape/ape.macho https://justine.lol/ape.macho || exit
|
||||||
|
else
|
||||||
|
curl -Rso o//ape/ape.elf https://justine.lol/ape.elf || exit
|
||||||
|
curl -Rso o//ape/ape.macho https://justine.lol/ape.macho || exit
|
||||||
|
fi
|
||||||
|
chmod +x o//ape/ape.elf || exit
|
||||||
|
chmod +x o//ape/ape.macho || exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$(uname -s)" = "Darwin" ]; then
|
||||||
|
if ! [ /usr/bin/ape -nt o//ape/ape.macho ]; then
|
||||||
echo >&2
|
echo >&2
|
||||||
echo installing o//ape/ape.elf to /usr/bin/ape >&2
|
echo "installing o//ape/ape.elf to /usr/bin/ape" >&2
|
||||||
echo sudo mv -f o//ape/ape.elf /usr/bin/ape >&2
|
echo "$SUDO mv -f o//ape/ape.elf /usr/bin/ape" >&2
|
||||||
sudo mv -f o//ape/ape.elf /usr/bin/ape || exit
|
$SUDO cp -f o//ape/ape.macho /usr/bin/ape || exit
|
||||||
echo done >&2
|
echo "done" >&2
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if ! [ /usr/bin/ape -nt o//ape/ape.elf ]; then
|
||||||
|
echo >&2
|
||||||
|
echo "installing o//ape/ape.elf to /usr/bin/ape" >&2
|
||||||
|
echo "$SUDO mv -f o//ape/ape.elf /usr/bin/ape" >&2
|
||||||
|
$SUDO cp -f o//ape/ape.elf /usr/bin/ape || exit
|
||||||
|
echo "done" >&2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# REGISTER APE LOADER WITH BINFMT_MISC TOO (LINUX-ONLY)
|
||||||
|
|
||||||
|
if [ x"$(uname -s)" = xLinux ]; then
|
||||||
|
|
||||||
if [ -e /proc/sys/fs/binfmt_misc/APE ]; then
|
if [ -e /proc/sys/fs/binfmt_misc/APE ]; then
|
||||||
echo >&2
|
echo >&2
|
||||||
echo it looks like APE is already registered with binfmt_misc >&2
|
echo it looks like APE is already registered with binfmt_misc >&2
|
||||||
|
echo To reinstall please run ape/apeuninstall.sh first >&2
|
||||||
echo please check that it is mapped to ape not /bin/sh >&2
|
echo please check that it is mapped to ape not /bin/sh >&2
|
||||||
echo cat /proc/sys/fs/binfmt_misc/APE >&2
|
echo cat /proc/sys/fs/binfmt_misc/APE >&2
|
||||||
cat /proc/sys/fs/binfmt_misc/APE >&2
|
cat /proc/sys/fs/binfmt_misc/APE >&2
|
||||||
# TODO: we need better uninstall recommendations
|
|
||||||
# the following works fine for justine
|
|
||||||
# but might remove unrelated software?
|
|
||||||
# sudo sh -c 'echo -1 >/proc/sys/fs/binfmt_misc/status'
|
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -41,8 +78,8 @@ if ! [ -e /proc/sys/fs/binfmt_misc ]; then
|
||||||
echo >&2
|
echo >&2
|
||||||
echo loading binfmt_misc into your kernel >&2
|
echo loading binfmt_misc into your kernel >&2
|
||||||
echo you may need to edit configs to persist across reboot >&2
|
echo you may need to edit configs to persist across reboot >&2
|
||||||
echo sudo modprobe binfmt_misc >&2
|
echo $SUDO modprobe binfmt_misc >&2
|
||||||
sudo modprobe binfmt_misc || exit
|
$SUDO modprobe binfmt_misc || exit
|
||||||
echo done >&2
|
echo done >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -50,14 +87,31 @@ if ! [ -e /proc/sys/fs/binfmt_misc/register ]; then
|
||||||
echo >&2
|
echo >&2
|
||||||
echo mounting binfmt_misc into your kernel >&2
|
echo mounting binfmt_misc into your kernel >&2
|
||||||
echo you may need to edit configs to persist across reboot >&2
|
echo you may need to edit configs to persist across reboot >&2
|
||||||
echo sudo mount -t binfmt_misc none /proc/sys/fs/binfmt_misc >&2
|
echo $SUDO mount -t binfmt_misc none /proc/sys/fs/binfmt_misc >&2
|
||||||
sudo mount -t binfmt_misc none /proc/sys/fs/binfmt_misc || exit
|
$SUDO mount -t binfmt_misc none /proc/sys/fs/binfmt_misc || exit
|
||||||
echo done >&2
|
echo done >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo >&2
|
echo >&2
|
||||||
echo registering APE with binfmt_misc >&2
|
echo registering APE with binfmt_misc >&2
|
||||||
echo you may need to edit configs to persist across reboot >&2
|
echo you may need to edit configs to persist across reboot >&2
|
||||||
echo 'sudo sh -c "echo '"'"':APE:M::MZqFpD::/usr/bin/ape:'"'"' >/proc/sys/fs/binfmt_misc/register"' >&2
|
echo '$SUDO sh -c "echo '"'"':APE:M::MZqFpD::/usr/bin/ape:'"'"' >/proc/sys/fs/binfmt_misc/register"' >&2
|
||||||
sudo sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register" || exit
|
$SUDO sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register" || exit
|
||||||
echo done >&2
|
echo done >&2
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
{
|
||||||
|
echo
|
||||||
|
echo "------------------------------------------------------------------"
|
||||||
|
echo
|
||||||
|
echo "APE INSTALL COMPLETE"
|
||||||
|
echo
|
||||||
|
echo "If you decide to uninstall APE later on"
|
||||||
|
echo "you may do so using ape/apeuninstall.sh"
|
||||||
|
echo
|
||||||
|
echo "Enjoy your APE loader (>'.')>"
|
||||||
|
echo
|
||||||
|
} >&2
|
||||||
|
|
24
ape/apeuninstall.sh
Executable file
24
ape/apeuninstall.sh
Executable file
|
@ -0,0 +1,24 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ "$UID" = "0" ]; then
|
||||||
|
SUDO=
|
||||||
|
else
|
||||||
|
SUDO=sudo
|
||||||
|
fi
|
||||||
|
|
||||||
|
{
|
||||||
|
echo
|
||||||
|
echo "APE Uninstaller intends to run"
|
||||||
|
echo
|
||||||
|
echo " $SUDO sh -c 'echo -1 >/proc/sys/fs/binfmt_misc/APE'"
|
||||||
|
echo " $SUDO rm -f /usr/bin/ape ~/.ape o/tmp/.ape /tmp/.ape"
|
||||||
|
echo
|
||||||
|
echo "You may then use ape/apeinstall.sh to reinstall it"
|
||||||
|
echo
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
if [ -f /proc/sys/fs/binfmt_misc/APE ]; then
|
||||||
|
$SUDO sh -c 'echo -1 >/proc/sys/fs/binfmt_misc/APE' || exit
|
||||||
|
fi
|
||||||
|
$SUDO rm -f /usr/bin/ape ~/.ape o/tmp/.ape /tmp/.ape || exit
|
|
@ -1610,11 +1610,6 @@ LSQLITE3 MODULE
|
||||||
project. Most of the unsupported APIs relate to pointers and database
|
project. Most of the unsupported APIs relate to pointers and database
|
||||||
notification hooks.
|
notification hooks.
|
||||||
|
|
||||||
redbean also currently disables SQLite features which don't make sense for
|
|
||||||
production serving, such as ALTER, VACUUM, ANALYZE, etc. For that reason
|
|
||||||
we provide an APE build of the SQLite shell which you can use to
|
|
||||||
administrate your redbean database. See the sqlite3.com download above.
|
|
||||||
|
|
||||||
|
|
||||||
────────────────────────────────────────────────────────────────────────────────
|
────────────────────────────────────────────────────────────────────────────────
|
||||||
RE MODULE
|
RE MODULE
|
||||||
|
|
Loading…
Reference in a new issue