Files
NetworkManager/examples/lua/lgi/change-vpn-username.lua
Thomas Haller 3b69f02164 all: unify format of our Copyright source code comments
```bash

readarray -d '' FILES < <(
  git ls-files -z \
    ':(exclude)po' \
    ':(exclude)shared/c-rbtree' \
    ':(exclude)shared/c-list' \
    ':(exclude)shared/c-siphash' \
    ':(exclude)shared/c-stdaux' \
    ':(exclude)shared/n-acd' \
    ':(exclude)shared/n-dhcp4' \
    ':(exclude)src/systemd/src' \
    ':(exclude)shared/systemd/src' \
    ':(exclude)m4' \
    ':(exclude)COPYING*'
  )

sed \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[-–] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C1pyright#\5 - \7#\9/' \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[,] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C2pyright#\5, \7#\9/' \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C3pyright#\5#\7/' \
  -e 's/^Copyright \(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/C4pyright#\1#\3/' \
  -i \
  "${FILES[@]}"

echo ">>> untouched Copyright lines"
git grep Copyright "${FILES[@]}"

echo ">>> Copyright lines with unusual extra"
git grep '\<C[0-9]pyright#' "${FILES[@]}" | grep -i reserved

sed \
  -e 's/\<C[0-9]pyright#\([^#]*\)#\(.*\)$/Copyright (C) \1 \2/' \
  -i \
  "${FILES[@]}"

```

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/298
2019-10-02 17:03:52 +02:00

70 lines
2.0 KiB
Lua
Executable File

#!/usr/bin/env lua
-- SPDX-License-Identifier: GPL-2.0+
--
-- Copyright (C) 2015 Red Hat, Inc.
--
-- This example changes username in a VPN profile.
-- The example uses libnm library using GObject introspection via Lua lgi module.
-- Most distribution ship the module as lua-lgi package.
-- libnm guide: https://developer.gnome.org/libnm/1.0/
-- Lua-lgi guide: https://github.com/pavouk/lgi/blob/master/docs/guide.md
local lgi = require 'lgi'
local NM = lgi.NM
-- mapping from VPN type to username data item
vpn2username = {
openvpn = "username",
vpnc = "Xauth username",
pptp = "user",
l2tp = "user",
openswan = "leftxauthusername",
}
---------------------------
-- Main code starts here --
---------------------------
-- parse command-line arguments
local profile, username, extra = ...
if (not profile or not username or extra) then
print(string.format("Usage: %s <vpn_profile> <username>", arg[0]:gsub(".*/","")))
os.exit(1)
end
-- get client object
client = NM.Client.new()
-- find the connection profile
con = client:get_connection_by_id(profile)
if not con then con = client:get_connection_by_uuid(profile) end
if not con then con = client:get_connection_by_path(profile) end
if not con then io.stderr:write(string.format("Profile %s not found.\n", profile)) os.exit(1) end
if not con:is_type(NM.SETTING_VPN_SETTING_NAME) then
io.stderr:write(string.format("Profile '%s' is not a VPN.\n", profile))
os.exit(1)
end
-- get VPN setting
vpn = con:get_setting_vpn()
service_name = vpn:get_service_type()
vpn_type = service_name:match(".*%.(.*)")
if not vpn2username[vpn_type] then
io.stderr:write(string.format("Unknown VPN type '%s'.\n", vpn_type))
os.exit(1)
end
-- update the username
vpn:add_data_item(vpn2username[vpn_type], username)
-- save changes
ok, errmsg = con:commit_changes(true)
if not ok then
io.stderr:write(string.format("Error in updating connection: %s.\n", errmsg))
os.exit(1)
end
print(string.format("Username updated to '%s'.", username))