Difference between revisions of "Hakchi:Variables and Functions"

From hakchi
Jump to: navigation, search
(b0030_package)
(b0010_functions)
Line 60: Line 60:
  
 
=== b0010_functions ===
 
=== b0010_functions ===
 +
<code>b0010_functions</code> contains general functions useful for [[hmod|hmods]]
 
==== squashDevice ====
 
==== squashDevice ====
==== unmountSquash ====
+
Prints the device that contains the [[squashfs]] filesystem.
 +
 
 
==== mountSquash ====
 
==== mountSquash ====
 +
Mounts the [[squashfs]] to [[Hakchi:Variables and Functions#squashfs|$squashfs]]
 +
 +
==== umountSquash ====
 +
Unmounts the [[squashfs]] from <code>[[Hakchi:Variables and Functions#squashfs|$squashfs]]</code>
 +
 
==== mount_base ====
 
==== mount_base ====
==== unmount_base ====
+
Mounts the [[user data partition]] at <code>[[Hakchi:Variables and Functions#mountpoint|$mountpoint]/var/lib] and calls <code>mountSquash</code>.
 +
 
 +
==== umount_base ====
 +
Unmounts the [[user data partition]] at <code>[[Hakchi:Variables and Functions#mountpoint|$mountpoint]/var/lib] and calls <code>umountSquash </code>.
 +
 
 
==== remove_old ====
 
==== remove_old ====
 
==== mod_repair_etc ====
 
==== mod_repair_etc ====
Line 78: Line 89:
 
==== early_getty ====
 
==== early_getty ====
 
==== copy ====
 
==== copy ====
 +
An helper function that calls <code>rsync -ac $1 $2</code> and also creates the destination directory if needed
 +
 
==== copy_mask ====
 
==== copy_mask ====
 
==== restore ====
 
==== restore ====
 +
Repairs the directory specified using the original files from [[squashfs]]
 +
 
==== mount_bind ====
 
==== mount_bind ====
 +
Unmounts the destination directory if there's already a mount point at that location and then runs <code>mount -o bind "$1" "$2"</code>
 +
 
==== overmount ====
 
==== overmount ====
 +
Uses <code>mount_bind</code> to overmount the specified directory from [[Hakchi:Variables and Functions#rootfs|$rootfs]] onto the normal path used by the system or alternatively, you can specify an alternate destination directory.
 +
 +
Example 1: overmounts <code>[[Hakchi:Variables and Functions#rootfs|$rootfs]]/bin</code> onto <code>/bin</code>
 +
<pre>overmount "/bin"</pre>
 +
 +
Example 2: overmounts <code>[[Hakchi:Variables and Functions#rootfs|$rootfs]]/backgrounds</code> onto <code>/usr/share/backgrounds</code>
 +
<pre>overmount "/backgrounds" "/usr/share/backgrounds"</pre>
 +
 
==== containsGames ====
 
==== containsGames ====
 +
Checks if the specified directory exists and contains game folders, if success, return an exit code of 0 or otherwise, return an exit code of 1.
 
==== linkGames ====
 
==== linkGames ====
 
==== softwareCheck ====
 
==== softwareCheck ====
Line 124: Line 150:
  
 
==== stopTask ====
 
==== stopTask ====
 +
Stops the specified process name and returns when the process has ended.
 +
 
==== waitTask ====
 
==== waitTask ====
 +
Waits until the specified process name is no longer running and returns.
 +
 
==== showImage ====
 
==== showImage ====
 
Displays the png image file passed as the first argument.
 
Displays the png image file passed as the first argument.
Line 132: Line 162:
  
 
==== hwmon ====
 
==== hwmon ====
 +
An alias for <code>cat "/sys/devices/virtual/hwmon/hwmon1/temp1_input"</code>
 +
 
==== usedBlockSpace ====
 
==== usedBlockSpace ====
 
Displays the number of 1024KB blocks used by the volume passed as the first argument.
 
Displays the number of 1024KB blocks used by the volume passed as the first argument.

Revision as of 20:43, 30 May 2018

There are a number of functions and variables available in hakchi for use in scripts.

Contents

Variables

If you have a standalone script and would like to read one of these variables, /bin/hakchi get can be used with the variable name as the first parameter.

If you're in a preinit.d script, you can access the variable directly.

modname

The name of the mod, this is set to hakchi

modpath

The mod path, this is set to /$modname

mountpoint

Depending on if the system is in preinit or normal boot, this can be one of two values, /newroot or nothing

installpath

The location that hakchi is installed to, set to $mountpoint/var/lib/$modname

firmwarepath

The location on nand that hakchi will search for the default hsqs image in, set to $installpath/firmware

extfirmwarepath

The location on external storage that hakchi will search for the default hsqs image in, set to $mountpoint/media/$modname/firmware

rootfs

The rootfs folder containing folders that get overmounted on top of the stock ones, set to $installpath/rootfs

squashfs

A mount point containing the original squashfs image, set to $mountpoint/var/squashfs

preinit

The location of the preinit loader file, set to $rootfs/etc/preinit

preinitpath

The location of the preinit.d folder, set to $preinit.d

sftype

The type of system currently booted, it can be one of two values: nes or snes

sfregion

The region of the system currently booted, it can be one of the following values:

  • usa
  • eur
  • jpn

gamepath

The location of the original game path that gets overmounted with the custom games

profilepath

The location of the user profile containing save data among other things, set to /var/lib/clover/profiles/0

temppath

The temporary directory, set to /tmp

Functions

If you have a standalone script and would like to run one of these functions, /bin/hakchi can be used with the function name as the first parameter.

If you're in a preinit.d script, you can call the function directly.

b0010_functions

b0010_functions contains general functions useful for hmods

squashDevice

Prints the device that contains the squashfs filesystem.

mountSquash

Mounts the squashfs to $squashfs

umountSquash

Unmounts the squashfs from $squashfs

mount_base

Mounts the user data partition at [[Hakchi:Variables and Functions#mountpoint|$mountpoint]/var/lib] and calls mountSquash.

umount_base

Unmounts the user data partition at [[Hakchi:Variables and Functions#mountpoint|$mountpoint]/var/lib] and calls umountSquash .

remove_old

mod_repair_etc

mod_repair_modules

mount_move

remount_root

checkFirmware

currentFirmware

overmountModules

loadFirmware

shutdown

reboot

early_getty

copy

An helper function that calls rsync -ac $1 $2 and also creates the destination directory if needed

copy_mask

restore

Repairs the directory specified using the original files from squashfs

mount_bind

Unmounts the destination directory if there's already a mount point at that location and then runs mount -o bind "$1" "$2"

overmount

Uses mount_bind to overmount the specified directory from $rootfs onto the normal path used by the system or alternatively, you can specify an alternate destination directory.

Example 1: overmounts $rootfs/bin onto /bin

overmount "/bin"

Example 2: overmounts $rootfs/backgrounds onto /usr/share/backgrounds

overmount "/backgrounds" "/usr/share/backgrounds"

containsGames

Checks if the specified directory exists and contains game folders, if success, return an exit code of 0 or otherwise, return an exit code of 1.

linkGames

softwareCheck

repair_fonts

checkGamepath

checkPath

Checks for the existence of the path passed as the first argument and if it exists, prints the path and returns an exit code of 0

If the path doesn't exist, nothing will be printed and the function will return an exit code of 1

findGameSyncStorage

Prints the base directory that games should be synced to.

findGameStorage

Prints the path that is currently being used for the games or returns an exit code of 1 if no custom games are found.

overmount_games

uilist

Lists all processes currently using the display.

uikill

Kills all processes currently using the display.

uistop

Stops all processes currently using the display.

uistart

Starts the Nintendo UI

uipause

Suspends all processes using the display.

uiresume

Resumes all processes using the display.

gameover

Powers down the system.

printSoftwareInfo

Prints the system type and region

stopTask

Stops the specified process name and returns when the process has ended.

waitTask

Waits until the specified process name is no longer running and returns.

showImage

Displays the png image file passed as the first argument.

playSound

Plays the wav sound file passed as the first argument.

hwmon

An alias for cat "/sys/devices/virtual/hwmon/hwmon1/temp1_input"

usedBlockSpace

Displays the number of 1024KB blocks used by the volume passed as the first argument.

freeBlockSpace

Displays the remaining number of 1024KB blocks for the volume passed as the first argument.

usedSpace

Prints the amount of space used by a folder.

usedBy

A helper function that accepts one of the following variables and calls usedSpace with the corresponding path.

  • games
  • saves
  • mods
  • firmware

b0020_backup

backup_one

backup_nandb

backup_nandc

backup

dumpFirmware

b0030_package

The functions in b0030_package are used during hmod installation and management.

transfer_file

transfer_default

transfer_path

pack_upath

pack_install

pack_list

pack_uninstall

packs_install

packs_uninstall

b0040_usb

disableUsbDevice

switchToUsbDevice

switchToUsbHost

getUsbStorageIds

waitForStorageDevice

waitForUsbDevice

waitForMmcDevice

checkStorageDevice

checkExtStorage