Skip to content

Instantly share code, notes, and snippets.

@jvolker
Forked from quinkennedy/openframe_install.sh
Last active September 29, 2019 11:45
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 jvolker/7d61d2550261f838c473ea6f3111c458 to your computer and use it in GitHub Desktop.
Save jvolker/7d61d2550261f838c473ea6f3111c458 to your computer and use it in GitHub Desktop.
wget/curl-able installation script for Openframe
#!/usr/bin/env bash
# Contributed by @quinkennedy (https://gist.github.com/quinkennedy/fc78c2bb1d6b1e27c174)
# modified to create images rather than installs by Jeremias Volker http://github.com/jvolker
{ # this ensures the entire script is downloaded #
openframe_has() {
type "$1" > /dev/null 2>&1
}
if [ -z "$OPENFRAME_DIR" ]; then
OPENFRAME_DIR="$HOME/.openframe"
fi
openframe_edit_or_add() {
if grep -q "^$2" $1; then
sudo bash -c "sed -i 's/^$2.*/$2$3/g' $1"
else
sudo bash -c "echo $2$3 >> $1"
fi
}
openframe_download() {
if openframe_has "curl"; then
curl -q $*
elif openframe_has "wget"; then
# Emulate curl with wget
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
-e 's/-L //' \
-e 's/-I /--server-response /' \
-e 's/-s /-q /' \
-e 's/-o /-O /' \
-e 's/-C - /-c /')
wget $ARGS
fi
}
openframe_do_rotate() {
echo "how much have you rotated it?"
echo "enter '0' for no rotation"
echo "'1' if you rotated your physical screen 90 degrees clockwise"
echo "'2' for 180 degrees (upside down)"
echo "'3' for 270 degrees (90 degrees counter-clockwise)"
read ANSWER
if [ "$ANSWER" -ge 0 -a "$ANSWER" -le 3 ]; then
openframe_edit_or_add /boot/config.txt display_rotate= $ANSWER
else
echo "input not recognised, must be a number between 0 and 3"
openframe_ask_rotate
fi
}
openframe_ask_rotate() {
echo "have you rotated your screen from default (normally landscape)? (y/n)"
read ANSWER
ANSWER="$(echo $ANSWER | tr '[:upper:]' '[:lower:]')"
if [ "$ANSWER" == "y" ] || [ "$ANSWER" == "yes" ]; then
openframe_do_rotate
elif [ "$ANSWER" == "n" ] || [ "$ANSWER" == "no" ]; then
:
else
echo "input not recognised, must be yes or no"
openframe_ask_rotate
fi
}
openframe_do_install() {
# install NVM for easy node version management
openframe_download https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
# source nvm to access it in the shell
# usually it is sourced in .bashrc,
# but we can't reload .bashrc within a script
echo "source nvm"
. ~/.nvm/nvm.sh
# install Node.js 4.3
echo "install node"
nvm install 6.9
nvm alias default 6.9
# disable terminal screen blanking
openframe_edit_or_add ~/.bashrc "setterm -powersave off -blank 0"
# disable screensaver
echo "install server utils"
sudo apt-get -y install x11-xserver-utils
# let anybody use xinit
openframe_edit_or_add /etc/X11/Xwrapper.config "allowed_users" "=anybody"
# echo "disable screensaver"
# TODO - this doesn't actually have the desired effect, and breaks startx
#touch ~/.xinitrc
#openframe_edit_or_add ~/.xinitrc "xset s off"
#openframe_edit_or_add ~/.xinitrc "xset -dpms"
#openframe_edit_or_add ~/.xinitrc "xset s noblank"
# install Openframe
echo "install openframe"
npm install -g openframe@latest
echo "install default format extensions"
npm install -g openframe-image@latest
npm install -g openframe-glslviewer@latest
npm install -g openframe-website@latest
npm install -g openframe-video@latest
# interactive prompt for configuration
# openframe_ask_rotate
echo "installed openframe"
# echo "If you have changed your display rotation, you must restart the Pi by typing: sudo reboot"
# echo ""
# echo "If not, you must run the following command: source ~/.bashrc"
# echo ""
# echo "After restarting or reloading .bashrc, you can launch the frame by just typing:"
# echo ""
# echo "openframe"
}
# change hostname
sudo raspi-config nonint do_hostname OpenframeRaspi
# change boot mode to command line
sudo raspi-config nonint do_boot_behaviour B2
# change password
curl https://raw.githubusercontent.com/davidferguson/pibakery-blocks/0bbaf2e0b3eb628177a180b803be8d706a7edfe1/changepass/changepass.py --output changepass.py && sudo python changepass.py openframe
# update all packages
if [ -z "$1" ] || [ "$1" != "--skipUpdatePackages" ] ; then
sudo apt-get update && sudo apt-get -y upgrade
fi
# set GPU memory to 256 to make shaders and image extension work
sudo raspi-config nonint do_memory_split 256
# disable SSH on reboot
sudo raspi-config nonint do_ssh 0
# finally install openframe
openframe_do_install
echo "all done. shutdown the pi and backup the image: sudo init 0"
} # this ensures the entire script is downloaded #
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment