-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathprune_4nco_global.sh
executable file
·144 lines (130 loc) · 3.52 KB
/
prune_4nco_global.sh
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
# This script removes or restores directories and/or files found in
# the rlist below from the current working directory. This script
# is intended to be executed when NCO implements GFS DA updates.
# NCO does not want package installations for operations to include
# non-operational code. This script removes directories and files
# not used by operations from the installation directory.
#
# Two modes are supported: prune, restore
# prune: use git rm -r to remove directories and files.
# The directories and files to remove are found
# in rlist below
# restore: use git RESET head and git checkout to restore
# removed directories and files
#
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
set -ex
mode=$1
# Check mode and set string
if [[ "$mode" = "prune" ]]; then
string="rm -r"
elif [[ "$mode" = "restore" ]]; then
git_ver=$(git version | cut -d" " -f3)
if [ $(version $git_ver) -lt $(version "2.23.0") ]; then
use_checkout="YES"
string="checkout"
else
use_checkout="NO"
string="restore"
fi
else
echo " "
echo "***ERROR*** invalid mode= $mode"
echo " valid modes are prune or restore"
echo " "
exit
fi
# Set root directory
readonly topdir=$(cd "$(dirname "$(readlink -f -n "${BASH_SOURCE[0]}" )" )/.." && pwd -P)
cd $topdir
echo " "
echo "Execute git $string in $topdir"
echo " "
# Process top level directories
cd $topdir
rlist="regression src/GSD unit-tests"
for type in $rlist; do
if [[ "$mode" = "prune" ]]; then
if [ -e $type ]; then
git $string ${type}*
rc=$?
if [[ $rc -ne 0 ]]; then
echo "***ERROR*** git $string ${type}"
exit
fi
fi
elif [[ "$mode" = "restore" ]]; then
if [[ "$use_checkout" = "YES" ]]; then
git reset HEAD ${type}*
git checkout ${type}*
rc=$?
else
git restore --staged ${type}*
git restore ${type}*
rc=$?
fi
if [[ $rc -ne 0 ]]; then
echo "***ERROR*** restore failed for ${type}"
exit
fi
fi
done
# Process doc directories and files
cd $topdir/doc
rlist="EnKF_user_guide GSI_user_guide README.discover Release_Notes.fv3gfs_da.v15.0.0.txt Release_Notes.gfsda.v16.0.0.txt"
for type in $rlist; do
if [[ "$mode" = "prune" ]]; then
if [ -e $type ]; then
git $string ${type}*
rc=$?
if [[ $rc -ne 0 ]]; then
echo "***ERROR*** git $string ${type}"
exit
fi
fi
elif [[ "$mode" = "restore" ]]; then
if [[ "$use_checkout" = "YES" ]]; then
git reset HEAD ${type}*
git checkout ${type}*
rc=$?
else
git restore --staged ${type}*
git restore ${type}*
rc=$?
fi
if [[ $rc -ne 0 ]]; then
echo "***ERROR*** restore failed for ${type}"
exit
fi
fi
done
# Process ush directories and files
cd $topdir/ush
rlist="sub"
for type in $rlist; do
if [[ "$mode" = "prune" ]]; then
if [ -e $type ]; then
git $string ${type}*
rc=$?
if [[ $rc -ne 0 ]]; then
echo "***ERROR*** git $string ${type}"
exit
fi
fi
elif [[ "$mode" = "restore" ]]; then
if [[ "$use_checkout" = "YES" ]]; then
git reset HEAD ${type}*
git checkout ${type}*
rc=$?
else
git restore --staged ${type}*
git restore ${type}*
rc=$?
fi
if [[ $rc -ne 0 ]]; then
echo "***ERROR*** restore failed for ${type}"
exit
fi
fi
done