<commit_before>package cmd

import (
	"bytes"
	"fmt"
	"html/template"
	"os"
	"os/exec"

	clientcmd "github.com/dpb587/ssoca/client/cmd"
	"github.com/jessevdk/go-flags"

	bosherr "github.com/cloudfoundry/bosh-utils/errors"
	boshsys "github.com/cloudfoundry/bosh-utils/system"
)

var tunnelblickConnectionScript = template.Must(template.New("script").Parse(`#!/bin/bash

set -u

name="$( basename "$( dirname "$( dirname "$( dirname "$0" )" )" )" )"
shadow="$( dirname "$0" )/config.ovpn"

file="/Users/$USER/Library/Application Support/Tunnelblick/Configurations/$name/Contents/Resources/config.ovpn"

echo "generating profile"
{{.Exec}} --config "{{.Config}}" --environment "{{.Environment}}" openvpn create-profile --service "{{.Service}}" > "$file.tmp"
exit=$?

if [[ "0" != "$?" ]]; then
  rm "$file.tmp"

  exit $exit
fi

set -e

mv "$file.tmp" "$file"

echo "updating shadow copy"g
cp "$file" "$shadow"
`))

type CreateTunnelblickProfile struct {
	clientcmd.ServiceCommand
	clientcmd.InteractiveAuthCommand

	SssocaExec string                       `long:"exec-ssoca" description:"Path to the ssoca binary"`
	Name       string                       `long:"name" description:"Specific file name to use for *.tblk"`
	Args       CreateTunnelblickProfileArgs `positional-args:"true"`

	FS        boshsys.FileSystem
	GetClient GetClient
}

var _ flags.Commander = CreateTunnelblickProfile{}

type CreateTunnelblickProfileArgs struct {
	DestinationDir string `positional-arg-name:"DESTINATION-DIR" description:"Directory where the *.tblk profile will be created (default: $PWD)"`
}

func (c CreateTunnelblickProfile) Execute(args []string) error {
	configManager, err := c.Runtime.GetConfigManager()
	if err != nil {
		return bosherr.WrapError(err, "Getting config manager")
	}<commit_msg>openvpn: improve tunnelblick profile reliability<commit_after>package cmd

import (
	"bytes"
	"fmt"
	"html/template"
	"os"
	"os/exec"

	clientcmd "github.com/dpb587/ssoca/client/cmd"
	"github.com/jessevdk/go-flags"

	bosherr "github.com/cloudfoundry/bosh-utils/errors"
	boshsys "github.com/cloudfoundry/bosh-utils/system"
)

var tunnelblickConnectionScript = template.Must(template.New("script").Parse(`#!/bin/bash

set -u

name="$( basename "$( dirname "$( dirname "$( dirname "$0" )" )" )" )"
shadow="$( dirname "$0" )/config.ovpn"

file="/Users/$USER/Library/Application Support/Tunnelblick/Configurations/$name/Contents/Resources/config.ovpn"

echo "renewing profile"
{{.Exec}} --config "{{.Config}}" --environment "{{.Environment}}" openvpn create-profile --service "{{.Service}}" > "$file.tmp"
exit=$?

if [[ "0" != "$exit" ]]; then
  rm "$file.tmp"

  echo "exiting with failure"
  exit $exit
fi

set -e

echo "writing profile"
mv -f "$file.tmp" "$file"

echo "updating shadow copy"
cp "$file" "$shadow"
`))

type CreateTunnelblickProfile struct {
	clientcmd.ServiceCommand
	clientcmd.InteractiveAuthCommand

	SssocaExec string                       `long:"exec-ssoca" description:"Path to the ssoca binary"`
	Name       string                       `long:"name" description:"Specific file name to use for *.tblk"`
	Args       CreateTunnelblickProfileArgs `positional-args:"true"`

	FS        boshsys.FileSystem
	GetClient GetClient
}

var _ flags.Commander = CreateTunnelblickProfile{}

type CreateTunnelblickProfileArgs struct {
	DestinationDir string `positional-arg-name:"DESTINATION-DIR" description:"Directory where the *.tblk profile will be created (default: $PWD)"`
}

func (c CreateTunnelblickProfile) Execute(args []string) error {
	configManager, err := c.Runtime.GetConfigManager()
	if err != nil {
		return bosherr.WrapError(err, "Getting config manager")
	}
{'fraction_non_alphanumeric': 0.14753204254158714, 'fraction_numerical': 0.00327242977911099, 'mean_word_length': 4.346938775510204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6611011', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1199, 'n_words': 277}