Skip to content

How to Contribute

theofficialgman edited this page Dec 20, 2021 · 10 revisions

How do I write a script?

Usually the scripts as part of the megascript start off with other developer documentation at the repository of the game/application/program that you are trying to automate setting up.

Every script in this repo can be used as reference material for how to write to a file as root, how to prompt the user for input, and many more examples throughout the scripts.

The available functions

All available functions can be found in the functions.sh file
A few of the most important functions are detailed below

error

This function is used to stop a script and write a line of red text to the terminal if a particular command reports an error code (like if a make install fails).
If a script errors, the log files for running that script can be optionally sent to our Discord in a channel with message history turned off for everyone except staff.
Usage is as follows:

sudo apt install exampleprogramname || error "something is wrong with the user's repositories, or their internet dropped out while installing a dependency"
# other stuff would go here
make -j4 || error "cmake failed to complete"

get_system

This function saves the jetson_model and architecture variables for use within the scripts:

jetson_model contains one of: tegra-2, tegra-3, tegra-4, tegra-x1, tegra-x2, xavier or an empty string
refer to the box64.sh script for a good use of the jetson_model type to change cmake options when configuring box64

dpkg_architecture contains the main dpkg cpu type: arm64, armhf, i386, amd64, etc
refer to the edex-ui.sh script for a good example of architecture variable in action

package_available

The L4T Megascript primarily targets Ubuntu 18.04, since that's what Nvidia and the Switchroot team both officially support, but if you'll look over the code you'll see we believe it's important to support future Ubuntu revisions going forward. In 18.04, qt5-default is a package that sets Qt5 to be the default Qt version, as well as providing a default configuration for qtchooser. It's needed for a few of our scripts; however, it doesn't exist in Ubuntu versions higher than 20.04. To speed up useless attempts at installing a program that doesn't exist, the ocs-url script uses this function to see if qt5-default is available, then only installs it if it can be installed.

package_available qt5-default
if [[ $? == "0" ]]; then
  sudo apt install -y qt5-default || error "Failed to install dependencies"
fi

ppa_installer and ppa_purger

These functions simply automate the yes/no response to adding or removing a PPA (and in the case of removing a PPA, our ppa_purger also removes the PPA's packages with it). For example, instead of

sudo add-apt-repository ppa:theofficialgman/opt-qt-5.15.2-bionic-arm

we use the following (syntax is the same for ppa_purger):

ppa_name="theofficialgman/opt-qt-5.15.2-bionic-arm" && ppa_installer

userinput_func

This function prompts the user for input through a GUI (zenity) or CLI (dialog) interface.
Its easiest to explain through an example usecase so one is given below:

description="This is an example of how to get user input.\
\nYou can print to multiple lines as shown here.
\n\n The table below can contain list of desired options that are passed as the variable `output`"
table=("yes" "no" "maybe")
userinput_func "$description" "${table[@]}"
if [[ $output == "yes" ]]; then
  echo "You chose yes"
elif [[ $output == "no" ]]; then
  echo "You chose no"
elif [[ $output == "maybe" ]]; then
  echo "What do you mean maybe? "
fi
Clone this wiki locally