#!/bin/bash

#if [[ $UID == 0 ]]; then
#	(>&2 echo "DO NOT run with sudo. Just run ")
#	echo "$usage"
#	exit 1
#fi

if [ ! -d $HOME/.PicoScenes ]; then
    mkdir $HOME/.PicoScenes/
fi

dialog --title "User Information Collection" --msgbox "\n PicoScenes License Plan (PSLP) requires some most basic affiliation/organization information. This information is only used for bug tracking and technical support.\n" 15 70
affiliation=$(dialog --title "User Information Collection (Step 1/3)" --inputbox "\n Step 1, please enter your affiliation/organization. \n An example could be \"Xidian University, Xi'an, China\"." 15 70 3>&1 1>&2 2>&3 3>&-)
computerId=$(dialog --title "User Information Collection (Step 2/3)" --inputbox "\n Step 2, please enter a name/ID for this specific computer. This ID shall to be unique across your lab or organization. \n An example could be \"Dr. Jiang's ThinkPad X1\"." 15 70  3>&1 1>&2 2>&3 3>&-)
licenseeName=$(dialog --title "User Information Collection (Step 3/3)" --inputbox "\n Step 3, please enter your name or the name of your research leader. For Power User License (PUL) subscriber, this name should be the actual licensee name. \n An example could be \"Prof. Rui Li\"." 15 70  3>&1 1>&2 2>&3 3>&-)

echo "{\"Affiliation\": \"$affiliation\", \"UserName\": \"$licenseeName\", \"ComputerID\": \"$computerId\"}" > $HOME/.PicoScenes/UserProfile.json
dialog --title "User Information Collection, Done!" --msgbox "\n The following information has been saved to $HOME/.PicoScenes/UserProfile.json \n ------------------------------------\n Affiliation : $affiliation \n Computer ID : $computerId \n User Name   : $licenseeName \n ------------------------------------ \n \n \n Thanks for your support!"  15 100



clear
# echo "-------------------------------------------------------------------"
# echo "Affiliation  : $affiliation"
# echo "Licensee Name: $licenseeName"
# echo "Computer ID  : $computerId"
# echo "-------------------------------------------------------------------"
