Skip to content

Instantly share code, notes, and snippets.

@Golit
Last active January 12, 2019 22:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Golit/85a2ae4b9adabc07d1d924dfd9da6137 to your computer and use it in GitHub Desktop.
Save Golit/85a2ae4b9adabc07d1d924dfd9da6137 to your computer and use it in GitHub Desktop.
Edit files on heroku with busybox vi
#!/bin/bash
# Downloads busybox to run vi on heroku
# Tested on heroku-16
# Fetch the version of busybox in the alpine repository
VERSION=$(curl -s -L http://dl-cdn.alpinelinux.org/alpine/latest-stable/main/x86_64/APKINDEX.tar.gz | tar -xzOf - APKINDEX | grep -A 12 -B 1 "^P:busybox-static$" | grep "^V:" | cut -c3-)
# Download busybox-static from the alpinelinux repository and extract the binary into /app/bin
# if the download fails visit the repository to check if the filename has changed
# The Output:
# tar: Ignoring unknown extended header keyword 'APK-TOOLS.checksum.SHA1'
# is not an error therefore we redirect it to /dev/null
URL_BUSYBOX_APK="http://dl-cdn.alpinelinux.org/alpine/latest-stable/main/x86_64/busybox-static-${VERSION}.apk"
curl -s -L ${URL_BUSYBOX_APK} | tar -C /app -xzf - 2> /dev/null || (echo "Downloading busybox from ${URL_BUSYBOX_APK} failed!"; exit 1)
# create symbolic link
ln -s /app/bin/busybox.static /app/bin/vi
# Now you are ready to edit your files
# run: $ vi
# cat busybox-vi-heroku.sh | grep -v "^#\|^$" | sha256sum
# sha256sum:7fc7424ec7f5dcb962a02cdf56dd24daf709fc805e2d0f1bbc6d7110b73a9b73 -

Download, verify and run script

url_busybox_vi_heroku="https://gist.githubusercontent.com/Golit/85a2ae4b9adabc07d1d924dfd9da6137/raw/busybox-vi-heroku.sh"
curl -s -L -o busybox-vi-heroku.sh ${url_busybox_vi_heroku}
[ "$(cat busybox-vi-heroku.sh | grep -v "^#\|^$" | sha256sum)" == "7fc7424ec7f5dcb962a02cdf56dd24daf709fc805e2d0f1bbc6d7110b73a9b73  -" ] && bash ./busybox-vi-heroku.sh
# Since /app/bin is in the $PATH you can launch vi like this:
vi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment