forked from NMAAHC/nmaahcmm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeymake
executable file
·76 lines (61 loc) · 4.6 KB
/
makeymake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/zsh
# set -x
# Function to begin the day and collect information
# btd() {
# Define ANSI escape codes for text colors and styles
GREEN='\033[0;32m' # Sets text color to green
ERROR='\033[0;31m' # Sets text color to red
ORANGE='\033[38;5;208m' # Sets text color to orange
NC='\033[0m' # Resets text color to default (No Color)
BOLD='\033[1m' # Makes text bold
NORMAL='\033[0m' # Resets text style to normal
# Get the current date in the format YYYYMMDD
DATE=$(date +"%Y%m%d")
# make a temp file for the json data
_maketemp(){
mktemp -q -t "$(basename "${0}")"
if [ "${?}" -ne 0 ]; then
echo "${0}: ${ERROR}Can't create temp file, exiting...${RESET}"
exit 1
fi
}
JSON_TEMP="$(_maketemp).json"
DIALOG_CMD_1="dialog --json --moveable --width 1000 --background color=#bc85fa --icon images/makeymake/NMAAHC_horiz_Smithsonian_purple.png --iconsize 400 --title none --messagefont color=white size=20 --messagealignment left --messageposition center --message 'Hello $USER!\n\n Please choose a directory in which to create all other directories.\n\n Default value is the current user desktop.' --infobox 'hey hey hey, welcome' --textfield 'Directory creation:, fileselect',value='/Users/$USER/Desktop',filetype='folder' --button2text 'Cancel'"
USER_INPUT_1=$(eval "$DIALOG_CMD_1")
#echo "USER INPUT is: $USER_INPUT_1"
CHOSEN_DIRECTORY=$(echo "$USER_INPUT_1" | jq -r '."Directory creation:"')
#echo "CHOSEN_DIRECTORY is: $CHOSEN_DIRECTORY"
if [[ -z "$CHOSEN_DIRECTORY" || ! -d "$CHOSEN_DIRECTORY" ]]; then
echo
echo "${ERROR}${BOLD}Error: No valid directory chosen or the chosen directory does not exist."
exit 1
fi
# run the dialog
DIALOG_CMD_2="dialog --json --moveable --width 75% --height 75% --background color=#0f011f --icon images/makeymake/NMAAHC_vert_purple.png --iconsize 300 --overlayicon /Users/bleakley/Desktop/NMAAHC_vert_purple.png --title none --messagefont size=13.5 --messagealignment left --messageposition top --message '**"$USER"**, please enter the following information for the collection being worked on:\n- **Collection ID:** The collection year and number together make up the NMAAHC collection ID. For example, 2012.79 represents the Pearl Bowser collection. The year indicates when the collection was acquired, and the number signifies the order it was acquired in that year. Do not include any leading zeros.\n- **Series Number:** Some collections, particularly archival ones, are assigned series numbers. In the Bowser collection, Series 1 is for film, Series 2 is for video, and Series 3 is for audio. Do not include any leading zeros. If there is no series in your collection, leave this blank.\n- **First Object:** Enter the number of the first object for which you would like a directory created. Do not include any leading zeros.\n- **Last Object:** Enter the number of the last object for which you want a directory created. The script will create directories for all numbers within the range of the first and last numbers.\n\n Your diectories will be created in **"$CHOSEN_DIRECTORY"**\n\n- The below information will create directories 2017_55_1_1 through 2017_55_1_12 on the user desktop:\n\n | Information | Value |
|-------------------|-------|
| Collection year | 2017 |
| Collection number | 55 |
| Series | 2 |
| First object | 1 |
| Last object | 12 |' --infobox 'hey hey hey, now you are here' --textfield 'Collection year:, prompt=2012' --textfield 'Collection number:, prompt=79' --textfield 'Series number, if applicable:, prompt=1' --textfield 'First object number:, prompt=16' --textfield 'Last object number:, prompt=87' --buttonstyle center --button1text 'Make My Directories!' --button2text 'Stop! I need to fix something!'"
USER_INPUT_2=$(eval "$DIALOG_CMD_2")
echo "${USER_INPUT_2}" > "${JSON_TEMP}"
# Read JSON file
COLLECTION_YEAR=$(jq -r '."Collection year:"' "${JSON_TEMP}")
COLLECTION_NUMBER=$(jq -r '."Collection number:"' "${JSON_TEMP}")
SERIES=$(jq -r '."Series number, if applicable:"' "${JSON_TEMP}")
FIRST_OBJECT=$(jq -r '."First object number:"' "${JSON_TEMP}")
LAST_OBJECT=$(jq -r '."Last object number:"' "${JSON_TEMP}")
# Iterate from the first object number to the last object number
for (( i=$first_object; i<=$last_object; i++ ))
do
# Define the directory name
if [[ -n $series && $series != "null" && $series != "" ]]; then
dir_name="${collection_year}_${collection_number}_${series}_${i}"
else
dir_name="${collection_year}_${collection_number}_${i}"
fi
# Create the directory
mkdir -p "${CHOSEN_DIRECTORY}/${dir_name}"
done
echo "Directories have been created successfully."