Command Execution Sample Code (os.execute)
os.execute depends on the shell; in a jailbroken iOS environment the shell might be bash or zsh.
The XXTouch TrollStore build cannot use os.execute.
Avoid os.execute whenever possible.
Reboot device
-- os.execute('reboot')
-- Use the following call instead
sys.reboot()
Respring device
-- os.execute('killall -9 SpringBoard;killall -9 backboardd')
-- Use the following call instead
sys.killall(9, 'SpringBoard', 'backboardd')
Rebuild icon cache
-- os.execute('su mobile -c uicache')
-- Use the following call instead
clear.caches()
Create a script log symlink in the script directory
-- os.execute('ln -s /private/var/mobile/Media/1ferver/log/sys.log /private/var/mobile/Media/1ferver/lua/scripts/脚本日志.txt')
-- Use the following call instead
lfs.link('/private/var/mobile/Media/1ferver/log/sys.log', '/private/var/mobile/Media/1ferver/lua/scripts/脚本日志.txt', true)
Common helper functions
--[[
The following wrappers are no longer recommended.
Use the built-in XXTouch file module functions instead.
--]]
local function sh_escape(path) -- XXTouch original function; you may use it commercially without XXTouch's permission
path = string.gsub(path, "([ \\()<>\'\"`#&*;?~$|])", "\\%1")
return path
end
function fdelete(path) -- Delete a file or directory (recursively delete children)
assert(type(path)=="string" and path~="", 'fremove argument error')
-- os.execute('rm -rf '..sh_escape(path))
-- Use the following call instead
file.remove(path)
end
function frename(from, to) -- Rename (move) a file or directory
assert(type(from)=="string" and from~="", 'frename arg #1 error')
assert(type(to)=="string" and to~="", 'frename arg #2 error')
-- os.execute('mv -f '..sh_escape(from).." "..sh_escape(to))
-- Use the following call instead
file.move(from, to, 'mo')
end
function fcopy(from, to) -- Copy a file or directory (recursively copy children)
assert(type(from)=="string" and from~="", 'fcopy arg #1 error')
assert(type(to)=="string" and to~="", 'fcopy arg #2 error')
-- os.execute('cp -rf '..sh_escape(from).." "..sh_escape(to))
-- Use the following call instead
file.copy(from, to, 'mo')
end
function mkdir(path) -- Create a directory (recursively create parents)
assert(type(path)=="string" and path~="", 'mkdir argument error')
-- os.execute('mkdir -p '..sh_escape(path))
-- Use the following call instead
file.mkdir_p(path)
end
-- Copy the wrapped functions above into your script before using them.
-- The following shows how to call them (no need to copy).
-- Delete /var/mobile/1.png
fdelete("/var/mobile/1.png")
-- Rename /var/mobile/2.png to /var/mobile/1.png
frename("/var/mobile/2.png", "/var/mobile/1.png")
-- Move /var/mobile/1.png to /var/mobile/Media/1ferver/res/3.png
frename("/var/mobile/1.png", "/var/mobile/Media/1ferver/res/3.png")
-- Copy /var/mobile/1.png to /var/mobile/Media/1ferver/res/4.png
fcopy("/var/mobile/1.png", "/var/mobile/Media/1ferver/res/4.png")
-- Create directory /var/mobile/1/2/3/4
mkdir("/var/mobile/1/2/3/4")