From 1e77a7b9e58e62654ca800f05b31c7467116c4bc Mon Sep 17 00:00:00 2001 From: dvs1 Date: Mon, 4 Nov 2024 12:32:17 +1000 Subject: Add uninstall and purge subcommands for PolygLua and aataaj. --- PolygLua.lua | 104 ++++++++++++++++++++++++++++++++++++++++++++++++----------- aataaj.lua | 47 ++++++++++++++++++++++++--- 2 files changed, 127 insertions(+), 24 deletions(-) diff --git a/PolygLua.lua b/PolygLua.lua index bd7bd4d..86dc8be 100755 --- a/PolygLua.lua +++ b/PolygLua.lua @@ -313,27 +313,93 @@ end -if arg[0] == './PolygLua.lua' then - local w = __[[whoami]]:noErr():Do().lines[1] - local d = __[[pwd]]:noErr():Do().lines[1] - local luas = __'ls -d1 /usr/share/lua/*':noErr():Do() - for i,l in ipairs(luas.lines) do - local lua = '/usr/local/share/lua/' .. l:sub(16) .. '/PolygLua.lua' - if _.exists(lua) then - print(lua .. ' installed') - else - if 'root' == w then - print('Installing ' .. lua) - __('mkdir -p /usr/local/share/lua/' .. l:sub(16) .. ' ; ln -s ' .. d .. '/PolygLua.lua ' .. lua):Do() - else - print(lua .. ' NOT installed') +_.who = __[[whoami]]:noErr():Do().lines[1] +_.dir = __[[pwd]]:noErr():Do().lines[1] + + + +if (arg[0] == './PolygLua.lua') or (arg[0] == 'PolygLua.lua') then + local options = + { + install = + { + help = 'Command to install PolygLua.lua', + func = function(self, options, a, args, i) + if 'root' ~= _.who then + E'Need to be root user to install.' + else + print('INSTALLING PolygLua.lua!!!') + + local luas = __'ls -d1 /usr/share/lua/*':noErr():Do() + for i,l in ipairs(luas.lines) do + local lua = '/usr/local/share/lua/' .. l:sub(16) .. '/PolygLua.lua' + if _.exists(lua) then + print(lua .. ' installed') + else + if 'root' == _.who then + print('Installing ' .. lua) + __('mkdir -p /usr/local/share/lua/' .. l:sub(16) .. ' ; ln -s ' .. _.dir .. '/PolygLua.lua ' .. lua):Do() + else + print(lua .. ' NOT installed') + end + end + end + + end +-- os.exit(0) end - end - end + }, + uninstall = + { + help = 'Command to uninstall PolygLua.lua', + func = function(self, options, a, args, i) + if 'root' ~= _.who then + E'Need to be root user to uninstall.' + else + print('UNINSTALLING PolygLua.lua!!!') + + local luas = __'ls -d1 /usr/share/lua/*':noErr():Do() + for i,l in ipairs(luas.lines) do + local lua = '/usr/local/share/lua/' .. l:sub(16) .. '/PolygLua.lua' + if _.exists(lua) then + if 'root' == _.who then + print('Uninstalling ' .. lua) + __('rm ' .. lua):Do() + end + end + end - if 'root' ~= w then - E'Need to be root user to install.' - end + end +-- os.exit(0) + end + }, + purge = + { + help = 'Command to purge PolygLua.lua', + func = function(self, options, a, args, i) + if 'root' ~= _.who then + E'Need to be root user to purge.' + else + print('PURGING PolygLua.lua!!!') + + local luas = __'ls -d1 /usr/share/lua/*':noErr():Do() + for i,l in ipairs(luas.lines) do + local lua = '/usr/local/share/lua/' .. l:sub(16) .. '/PolygLua.lua' + if _.exists(lua) then + if 'root' == _.who then + print('Purging ' .. lua) + __('rm ' .. lua):Do() + end + end + end + + end +-- os.exit(0) + end + }, + } + + _.parse(arg, options) end diff --git a/aataaj.lua b/aataaj.lua index 611059d..2a1f7e3 100755 --- a/aataaj.lua +++ b/aataaj.lua @@ -125,15 +125,13 @@ local options = { help = 'Command to install aataaj.lua', func = function(self, options, a, args, i) - local w = __[[whoami]]:noErr():Do().lines[1] - local d = __[[pwd]]:noErr():Do().lines[1] - if 'root' ~= w then + if 'root' ~= _.who then E'Need to be root user to install.' else print('INSTALLING!!!') __[[#!/bin/bash - echo "Installing PolygLua" - ./PolygLua.lua -vvvv + echo "Installing aataaj" + ./PolygLua.lua -vvvv install ln -s `pwd`/aataaj.lua /usr/local/bin/aataaj.lua ln -s /usr/local/bin/aataaj.lua /etc/init.d/aataaj.lua update-rc.d aataaj.lua defaults @@ -142,6 +140,45 @@ local options = os.exit(0) end }, + uninstall = + { + help = 'Command to uninstall aataaj.lua', + func = function(self, options, a, args, i) + if 'root' ~= _.who then + E'Need to be root user to uninstall.' + else + print('UNINSTALLING!!!') + __[[#!/bin/bash + echo "Uninstalling aataaj" + update-rc.d aataaj.lua remove + rm /etc/init.d/aataaj.lua + rm /usr/local/bin/aataaj.lua + ./PolygLua.lua -vvvv uninstall + ]]:log():show():Do() + end + os.exit(0) + end + }, + uninstall = + { + help = 'Command to purge aataaj.lua', + func = function(self, options, a, args, i) + if 'root' ~= _.who then + E'Need to be root user to purge.' + else + print('UNINSTALLING!!!') + __[[#!/bin/bash + echo "Uninstalling aataaj" + update-rc.d aataaj.lua remove + rm /etc/init.d/aataaj.lua + rm /usr/local/bin/aataaj.lua + ./PolygLua.lua -vvvv uninstall + rm -fr /var/lib/aataaj + ]]:log():show():Do() + end + os.exit(0) + end + }, } _.parse(arg, options, 'aataaj') -- cgit v1.1