Skip to content

Instantly share code, notes, and snippets.

@bokwoon95
Last active July 1, 2024 12:45
Show Gist options
  • Save bokwoon95/9ac84beb08d5769e09b4e3b102e5f16c to your computer and use it in GitHub Desktop.
Save bokwoon95/9ac84beb08d5769e09b4e3b102e5f16c to your computer and use it in GitHub Desktop.
Short few-liner commands to install Go on a new server
#!/usr/bin/env bash
sudo apt-get update -y
sudo apt-get install -y git tmux libvips libvips-tools sqlite3
sudo apt-get upgrade -y
curl --location --output go.tgz "https://dl.google.com/go/$(curl https://go.dev/dl/?mode=json | grep -o '"version": "go.*"' | head -n 1 | xargs | cut -d ' ' -f 2).linux-$(dpkg --print-architecture).tar.gz"
sudo tar -xzf go.tgz --directory /usr/local
rm go.tgz
sudo ln -sf /usr/local/go/bin/go /usr/local/bin/go
sudo ln -sf /usr/local/go/bin/gofmt /usr/local/bin/gofmt
sudo ln -sf "$HOME/go/bin/notebrew" /usr/local/bin/notebrew
if ! test -e "$HOME/nb10"; then
pushd "$HOME"
git clone https://github.com/bokwoon95/nb10
popd
else
pushd "$HOME/nb10"
git pull
popd
fi
echo '#!/usr/bin/env bash
set -e
set -u
set -o pipefail
INPUT_PATH="$1"
OUTPUT_PATH="$2"
if test ! -f "$INPUT_PATH"; then
echo "INPUT_PATH $INPUT_PATH does not exist"
exit 1
fi
width="$(vipsheader "$INPUT_PATH" -f width)"
height="$(vipsheader "$INPUT_PATH" -f height)"
scale_factor="$(awk -v "width=$width" -v "height=$height" "BEGIN {
aspect_ratio = width / height;
is_tall_img = aspect_ratio < 9 / 16;
if (is_tall_img || width > height) {
if (width <= 1080) {
print 1;
} else {
print 1080 / width;
}
} else {
if (height <= 1080) {
print 1;
} else {
print 1080 / height;
}
}
}")"
if test "$scale_factor" = "1"; then
mv "$INPUT_PATH" "$OUTPUT_PATH"
else
vips resize "$INPUT_PATH" "$OUTPUT_PATH" "$scale_factor"
echo "$INPUT_PATH: width = $width, old height = $height"
echo "$OUTPUT_PATH: width = $(vipsheader "$OUTPUT_PATH" -f width), height = $(vipsheader "$OUTPUT_PATH" -f height)"
fi' | sudo tee /usr/local/bin/imgresize > /dev/null
sudo chmod +x /usr/local/bin/imgresize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment