Skip to content

Instantly share code, notes, and snippets.

@mikhailnov
Last active January 14, 2020 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikhailnov/48235b3e4ab8d1729f65bdc76c150594 to your computer and use it in GitHub Desktop.
Save mikhailnov/48235b3e4ab8d1729f65bdc76c150594 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -efu
export DEBIAN_FRONTEND=noninteractive
FALLBACK=0
APT_MAIN=0
DONE=0
khpkg=""
kernel="$(uname -r || :)"
if [ -z "$kernel" ]; then
echo "Unable to get kernel version, trying fallback"
FALLBACK=1
fi
if [ "$FALLBACK" = 0 ] && [ ! -d "/lib/modules/${kernel}/kernel" ]; then
echo "Detected kernel not found on this sytem, probably running in container?"
echo "Trying fallback"
FALLBACK=1
fi
if [ "$FALLBACK" = 0 ]; then
khpkg="linux-headers-${kernel}"
if ! LC_ALL=C apt policy "$khpkg" | grep -q 'Unable to locate package'
then APT_MAIN=0
else APT_MAIN=1
fi
fi
if [ "$APT_MAIN" = 1 ]; then
if apt install -y "$khpkg" ; then
DONE=1
fi
fi
if [ "$DONE" = 0 ]; then
if apt install "blablabla" ; then
DONE=1
fi
fi
if [ "$DONE" = 0 ]; then
echo "Error"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment