diff options
Diffstat (limited to 'mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0010_functions')
-rw-r--r-- | mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0010_functions | 185 |
1 files changed, 145 insertions, 40 deletions
diff --git a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0010_functions b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0010_functions index ff726747..7ec99650 100644 --- a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0010_functions +++ b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0010_functions @@ -37,37 +37,57 @@ remove_old(){ } mod_repair_etc(){ + [ -d "$rootfs" ] || return 0 remove_old "$rootfs" - rm -f "$modpath/rootfs/etc/preinit.d/p0000_config" - chown -R 0:0 "$modpath/" local etc="$temppath/etc" rm -rf "$etc" mkdir -p "$etc" copy "$mountpoint/etc/" "$etc/" if [ "$1" == "full" ]; then + rm -f "$modpath/rootfs/etc/preinit.d/p0000_config" copy "$modpath/rootfs/etc/" "$etc/" else copy "$rootfs/etc/inittab" "$etc/inittab" fi copy "$etc/" "$rootfs/etc/" + rm -rf "$etc" } mod_repair_modules(){ - restore "/lib/modules/$(uname -r)/" + [ -d "$mountpoint/lib/modules/$(uname -r)" ] && restore "/lib/modules/$(uname -r)/" +} + +mount_move(){ + local tmpmount="/$2" + if [ "$1" == "l" ]; then + mountpoint -q "$mountpoint$tmpmount" || return 1 + mkdir -p "$tmpmount" + mount --move "$mountpoint$tmpmount" "$tmpmount" + else + mountpoint -q "$tmpmount" || return 1 + mount --move "$tmpmount" "$mountpoint$tmpmount" + rmdir --ignore-fail-on-non-empty "$tmpmount" + fi } remount_root(){ - local tmpmount="/var" - mkdir -p "$tmpmount" - mount --move "$mountpoint/var" "$tmpmount" + mount_move l media + mount_move l var umount "$mountpoint" + local loopfile="/var${1##$mountpoint/var}" + [ -f "$loopfile" ] || loopfile="/media${1##$mountpoint/media}" + if ! mount -o loop,ro,noatime "$loopfile" "$mountpoint"; then + local preinitf="/${preinit##$mountpoint/}" + local preinit="$preinitf" + cfg_firmware="_nand_" + save_config + shutdown + fi - local loopfile="$tmpmount${1##$mountpoint/var}" - mount -o loop,ro,noatime "$loopfile" "$mountpoint" || shutdown - - mount --move "$tmpmount" "$mountpoint/var" + mount_move r var + mount_move r media } checkFirmware(){ @@ -82,18 +102,19 @@ currentFirmware(){ echo "$firmware" return 0 fi - if [ -b /dev/mapper/root-crypt ]; then + if [ -b "/dev/mapper/root-crypt" ]; then echo "_nand_" return 0 fi return 1 } -load_firmware(){ +loadFirmware(){ [ -z "$(mount | grep -F loop0)" ] || return 1 local firmware="$mountpoint$cfg_firmware" if ! checkFirmware "$firmware"; then + [ "$cfg_firmware" == "auto" ] || return 0 [ -d "$firmwarepath" ] || return 0 firmware="$(find "$firmwarepath" -type f -name "*.hsqs" | sort | head -n 1)" fi @@ -114,8 +135,7 @@ load_firmware(){ } shutdown(){ - echo "shutting down..." - echo + echo "The system is going down NOW!" sync umount -a -r 2>/dev/null poweroff -f @@ -123,8 +143,7 @@ shutdown(){ } reboot(){ - echo "rebooting..." - echo + echo "Restarting system." sync umount -a -r 2>/dev/null /bin/reboot -f @@ -185,48 +204,121 @@ containsGames(){ return 0 } +linkGames(){ + local games="$mountpoint/media/$modname/games${1##$rootfs$gamepath}" + [ -d "$games" ] || games="$installpath/games${1##$rootfs$gamepath}" + [ -d "$games" ] || games="$1" + games="${games##$mountpoint}" + rm -f "$mountpoint/var/games" + ln -s "$games" "$mountpoint/var/games" + return 0 +} + +softwareCheck(){ + sftype="nes" + sfregion="usa" + [ "$(cat "$mountpoint/etc/clover/boardtype")" == "dp-shvc" ] && sftype="snes" + [ "$(cat "$mountpoint/etc/clover/REGION")" == "JPN" ] && sfregion="jpn" + [ "$(cat "$mountpoint/etc/clover/REGION")" == "EUR" ] && sfregion="eur" + + local feck="$mountpoint/var/lib/clover/profiles/0/home-menu/save/system-save.json" + if [ "$sftype" == "snes" ]; then + gamepath="/usr/share/games" + [ -f "$feck" ] && mv -f "$feck" "$feck.nes" + [ -d "$feck.snes" ] && rm -rf "$feck" && mv "$feck.snes" "$feck" + else + gamepath="/usr/share/games/nes/kachikachi" + [ -d "$feck" ] && rm -rf "$feck.snes" && mv "$feck" "$feck.snes" + [ -f "$feck.nes" ] && mv -f "$feck.nes" "$feck" + fi + + rm -f "$mountpoint/var/saves" + ln -s "/var/lib/clover/profiles/0" "$mountpoint/var/saves" +} + +repair_fonts(){ + if [ "$sftype" == "nes" ]; then + mkdir -p "$1" || return 1 + [ ! -f "$1/title.fnt" ] && (cp $rootfs$gamepath/title.fnt "$1" || cp $squashfs$gamepath/title.fnt "$1") + [ ! -f "$1/copyright.fnt" ] && (cp $rootfs$gamepath/copyright.fnt "$1" || cp $squashfs$gamepath/copyright.fnt "$1") + fi +} + +repair_games(){ + [ -w "$1" ] || return 0 + local usesymlink='' + ln -s / "$1/symlinktest" && rm "$1/symlinktest" && usesymlink='y' + + ls -1 "$squashfs$gamepath" | grep CLV- | while read code + do + local gamedir="$1/$code" + local squashgamedir="$squashfs$gamepath/$code" + + [ -d "$gamedir" ] || continue + + if [ ! -f "$gamedir/$code.desktop" ]; then + cp "$squashgamedir/$code.desktop" "$gamedir/" + [ "$sftype" == "nes" ] && \ + sed -i -e 's#/usr/bin/clover-kachikachi#/bin/clover-kachikachi-wr#g' "$gamedir/$code.desktop" + [ "$sftype" == "snes" ] && \ + sed -i -e 's#/usr/bin/clover-canoe-shvc#/bin/clover-canoe-shvc-wr#g' "$gamedir/$code.desktop" + fi + + [ -d "$gamedir/autoplay/" ] && ([ "$(ls -A "$gamedir/autoplay/")" ] || rm -r "$gamedir/autoplay/") + [ -d "$gamedir/pixelart/" ] && ([ "$(ls -A "$gamedir/pixelart/")" ] || rm -r "$gamedir/pixelart/") + + find "$squashgamedir" -maxdepth 1 | sed -n '1!p' | while read squashfile + do + if [ "$usesymlink" == "y" ]; then + ln -s "${squashfile##$mountpoint}" "$gamedir/" > /dev/null 2>&1 + else + rsync -a --ignore-existing "$squashfile" "$gamedir/" > /dev/null 2>&1 + fi + done + done + sync + return 0 +} + overmount_games(){ local menu_code="000" [ -f "$installpath/menu" ] && menu_code="$(cat "$installpath/menu")" - [ -z "$menu_code" ] && menu_code="000" + containsGames "$rootfs$gamepath/$menu_code" || menu_code="" echo "menu code: $menu_code" - if [ "$menu_code" != "000" ]; then - if containsGames "$rootfs$gamepath/$menu_code"; then - overmount "$gamepath/$menu_code" "$gamepath" && return 0 - else - echo "no romz found at: $rootfs$gamepath/$menu_code" - fi - fi - if containsGames "$rootfs$gamepath"; then - overmount "$gamepath" && return 0 + if containsGames "$rootfs$gamepath/$menu_code"; then + overmount "$gamepath/$menu_code" "$gamepath" && repair_games "$rootfs$gamepath/$menu_code" && linkGames "$rootfs$gamepath/$menu_code" && return 0 + else + echo "no romz found at: $rootfs$gamepath/$menu_code" fi - echo "no romz found at: $rootfs$gamepath" + linkGames "$gamepath" return 1 } +uilist(){ + lsof -n | grep -F "/dev/fb0" | awk '{print $1}' | sort -u +} + +uikill(){ + [ -z "$1" ] && return 1 + uilist | xargs -r kill -s "$1" +} + uistop(){ - killall -9 clover-mcp - killall -9 ReedPlayer-Clover - killall kachikachi - killall canoe-shvc - killall retroarch + killall -s KILL clover-mcp 1>/dev/null 2>&1 + uikill TERM } uistart(){ - uistop 1>/dev/null 2>&1 - /etc/init.d/S81clover-mcp start + uistop + sh "/etc/init.d/S81clover-mcp" start } uipause(){ - lsof -n | grep /dev/fb0 | awk '{ print $1 }' | while read pid; do - kill -s SIGSTOP $pid - done + uikill STOP } uiresume(){ - lsof -n | grep /dev/fb0 | awk '{ print $1 }' | while read pid; do - kill -s SIGCONT $pid - done + uikill CONT } gameover(){ @@ -237,3 +329,16 @@ printSoftwareInfo(){ echo "software=$sftype" echo "region=$sfregion" } + +showImage(){ + image="$(eval echo "$1")" + [ -f "$image" ] || image="$rootfs$1" + [ -f "$image" ] || image="$squashfs$1" + [ -f "$image" ] || return 1 + decodepng "$image" > "/dev/fb0" & + return 0 +} + +hwmon(){ + cat "/sys/devices/virtual/hwmon/hwmon1/temp1_input" +} |