Friday, March 16, 2018

YAD - Yet Another Dialog

What a wonderful tool for building graphical dialog boxes from Linux shells!

In imaging Windows computers for my workplace, I needed a graphical window to pop up to ask the technician for the computer's name and the Active Directory group into which it needed to be placed. I wound up building the tool using PowerShell.

After building the tool, I got to wondering what it would take to do the same thing in Linux, and finding the tool "YAD" (a souped-up alternative to Zenity, which is a souped-up alternative to Dialog, which is a souped-up version to just the command line), found it is a very powerful little utility for building GUI dialog boxes. ("aptitude install yad" will install it on your Debian system.)

There are a couple of good documents on the web for learning how to use this utility, so I won't try to provide any kind of tutorial. But I thought I'd share the script so that perhaps it might help someone see the bigger picture. Just copy the script to your Linux box, "chmod +x" it, and run it ("./GetComputerNameAndOU.sh").

#!/bin/bash

#            RENAME COMPUTER AND GET OU
#
# This script creates an input box with two
# fields, one for the computer name, and one
# for the computer's OU
#


### Set these constants
CONFIG_DIR="/tmp"           # Output of this script will be saved here,
CONFIG_FILE="config.txt"    # in this file.
DefaultName="ACUxxxxx"
ouDefaultLandZone="Computers,DC=acu,DC=loacl"    # If no OU is selected
# Final product = ouLeafNode + selected OU + ouBaseLandZone
ouBaseLandZone=",OU=Departments,DC=acu,DC=local"
ouLeafNode="OU=Computers,OU="

 
### Specify your Active Directory Organizational Units here.

### The line starting with a caret will be the default
### selection in the pull-down selection field.
ou=$(echo "\
^Not Specified,\
Abilene Library Consortium,\
Academic Development Center,\
Accounting,\
Accounting and Finance,\
ACU Foundation,\
ACU Police Department,\
ACU Press,\
Adams Center,\
Advancement,\
Advancement Services,\
Advancement Stewardship,\
Advancement Strategies,\
Advising Center,\
AG and Environmental Sciences,\
Alpha Scholars and Student Success,\
Alumni Relations,\
Alumni Relations, Annual Projects & University Relations,\
Analytics,\
Art and Design,\
Arts and Sciences,\
Athletics,\
Bible Missions and Ministry,\
Biblical Studies,\
Billings and Receivables,\
Biology,\
Brown Library,\
Brown Library Dean's Suite,\
Brown Library Technical Services,\
Business and Services,\
Campus Center,\
Campus Recruiting,\
Campus Visits,\
Campus Visits and Events,\
Career Center,\
CEHS Dean's Office,\
Center for Christian Service and Leadership,\
Chancellor's Office,\
Chemistry and Biochemistry,\
CIE,\
City Square,\
COBA,\
College of Arts anbd Science,\
College of Education and Human Services,\
Communication,\
Communication and Sociology,\
Communication Science and Disorder,\
Computing Services,\
Conflict Resolution,\
Construction and Risk Management,\
Creative Services,\
Distance Education,\
Doctor of Ministry Program,\
Electronic Resources and Serials,\
Engineering Physics,\
English,\
Enrollment Management,\
Enrollment Management & Student Engagement,\
Enrollment Marketing,\
Enterprise Infrastructure,\
Exercise Science and Health,\
Facilities and Campus Development,\
Facilities Management,\
Financial Operations,\
First Year Program,\
Foreign Languages,\
General Counsel,\
General Education,\
Graduate Admissions,\
Graduate School,\
Graduate School of Theology,\
Graduate Studies in Education,\
Griggs Center,\
Halbert Institute for Missions,\
History,\
Honors College,\
Human Resources,\
Information Technology,\
Institutional Effectivness,\
Investment Services,\
Journalism and Mass Communication,\
KACU,\
Kinesiology and Nutrition,\
Landscape and Grounds,\
Language and Literature,\
Learning Studio,\
Mail Services,\
Management Sciences,\
Marketing,\
Marketing Operations,\
Marriage and Family Therapy,\
Mathematics,\
McNair Scholars,\
Medical Care and Counseling Center,\
Medical Clinic,\
Ministry Events,\
Ministry Programs,\
Music,\
Occupational Therapy,\
Office and Research and Sponsored Programs,\
Online Marketing,\
Online Programs,\
Payroll,\
Physical Resources,\
Physics,\
Political Science,\
Political Science and Criminal Justice,\
President's Office,\
Provost,\
Pruett Gerontology Center,\
Psychology,\
Psychology Clinic,\
Public Relations,\
Public Services,\
Pura Vida Salon,\
Registrar,\
Residence Life,\
Retention and Student Services,\
School of Information Technology,\
School of Nursing,\
Service Learning and Volunteer Resources,\
Siburt Institute,\
Social Work,\
Sociology and Family Studies,\
Special Collections,\
Spiritual Formation Office,\
Spiritual Life,\
Spiritual Life and Chapel Programs,\
SRWC,\
Strategic Planning,\
Student Administrative Services,\
Student Financial Services,\
Student Leadership Development,\
Student Life,\
Systems and Operations,\
Talent Search,\
Teacher Education,\
Team55,\
Technology Support Services,\
Territory Recruitment,\
Test GPOs,\
TestMalwarebytesDeployment,\
The Campus Store,\
Theatre,\
University Counseling Center,\
University Events,\
University Procurement,\
University Relations,\
Upward Bound,\
Vice President for Student Life's Office,\
Video Production,\
WFF\
")


value=$(yad --width=400 --title="Name Computer & Select AD Org Unit" \
  --timeout=120 --timeout-indicator=bottom \
  --form \
    --item-separator="," \
    --field="Enter new computer name\:" \
    --field="\tAD Organizational Unit\:":CE \
    "$DefaultName" "$ou")

### Split response into an array
IFS="|" read -a val_array <<< "${value%;}"

### Convert Name to uppercase
val_array[0]=${val_array[0]^^}

### Save the values to config file
echo Name:${val_array[0]} > $CONFIG_DIR/$CONFIG_FILE
echo OUName:${val_array[1]} >> $CONFIG_DIR/$CONFIG_FILE
if [ $"{val_array[1]}" = "Not Selected" ]
then
  echo OU:$ouDefaultLandZone >> $CONFIG_DIR/$CONFIG_FILE
else
  echo OU:$ouLeafNode${val_array[1]}$ouBaseLandZone >> $CONFIG_DIR/$CONFIG_FILE
fi





Originally published at: 
https://kentwest.blogspot.com/2018/03/yad-yet-another-dialog.html

No comments: