2018-04-05 14:12:03 -07:00
|
|
|
import cmd from './cmd'
|
|
|
|
import tc from '@uci/try-catch'
|
|
|
|
|
2019-01-01 20:13:14 -08:00
|
|
|
async function apdelete(con) {
|
2018-04-05 14:12:03 -07:00
|
|
|
let ret = null
|
|
|
|
let filter = con.name || con.uuid
|
|
|
|
if (!filter) return new Error('no delete filter supplied')
|
2018-04-11 12:41:59 -07:00
|
|
|
let cmdStr = `nmcli --terse --fields UUID,name,type c show | grep 802-11-wireless | grep '${filter}'`
|
2018-04-05 14:12:03 -07:00
|
|
|
ret = await tc(cmd)(cmdStr)
|
2019-01-01 20:13:14 -08:00
|
|
|
if (ret.err || ret.res === '')
|
|
|
|
return new Error(`no connections to delete => ${ret.err.cmd}`)
|
2018-04-05 14:12:03 -07:00
|
|
|
let connections = ret.res.split('\n')
|
|
|
|
await connections.forEach(async acon => {
|
2019-01-01 20:13:14 -08:00
|
|
|
if (acon != '') {
|
|
|
|
// console returns an extra blank line
|
2018-04-05 14:12:03 -07:00
|
|
|
let fields = acon.replace(/\\:/g, '&&').split(':')
|
|
|
|
// console.log('deleting',fields[0],acon)
|
|
|
|
let cmdStr = `nmcli con delete uuid ${fields[0]}`
|
|
|
|
await tc(cmd)(cmdStr)
|
|
|
|
}
|
|
|
|
})
|
2018-04-11 12:41:59 -07:00
|
|
|
cmdStr = `nmcli --terse --fields uuid,name,type c show | grep 802-11-wireless | grep '${filter}'`
|
2018-04-05 14:12:03 -07:00
|
|
|
ret = await tc(cmd)(cmdStr)
|
2019-01-01 20:13:14 -08:00
|
|
|
if (ret.err || ret.res === '')
|
|
|
|
return { res: 'success all connections deleted', connnections: connections }
|
2018-04-05 14:12:03 -07:00
|
|
|
}
|
2019-01-01 20:13:14 -08:00
|
|
|
|
|
|
|
export default apdelete
|