File: cleanup

package info (click to toggle)
pcp 7.1.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 252,748 kB
  • sloc: ansic: 1,483,656; sh: 182,366; xml: 160,462; cpp: 83,813; python: 24,980; perl: 18,327; yacc: 6,877; lex: 2,864; makefile: 2,738; awk: 165; fortran: 60; java: 52
file content (147 lines) | stat: -rwxr-xr-x 2,798 bytes parent folder | download
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
145
146
147
#!/bin/sh
#
# Cleanup symlinks to match artifacts for CI QA runs
#

tmp=/var/tmp/ci-qa-cleanup-$$
status=1
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
SHOW_ME=false

if $SHOW_ME
then
    LN='echo + ln'
    RM='echo + rm'
else
    LN=ln
    RM=rm
fi

_shortname()
{
    case "$1"
    in
	test-centos-stream*)
	    echo "$1" | sed -e 's/test-centos-stream/c/' -e 's/-container//'
	    ;;
	test-debian*)
	    echo "$1" | sed -e 's/test-debian/d/' -e 's/-container//'
	    ;;
	test-fedora-rawhide-*)
	    echo "$1" | sed -e 's/test-fedora-rawhide/frh/' -e 's/-container//'
	    ;;
	test-fedora*)
	    echo "$1" | sed -e 's/test-fedora/f/' -e 's/-container//'
	    ;;
	test-ubuntu????-i386-*)
	    echo "$1" | sed -e 's/test-ubuntu/u3/' -e 's/..-i386//' -e 's/-container//'
	    ;;
	test-ubuntu????-container)
	    echo "$1" | sed -e 's/test-ubuntu/uc/' -e 's/..-container//'
	    ;;
	test-ubuntu????)
	    echo "$1" | sed -e 's/test-ubuntu/u/' -e 's/..$//'
	    ;;
	*)
	    echo >&2 "_shortname: Botch cannot handle $1"
	    ;;
    esac
}

artifacts_dir="$HOME/src/pcp/ci-qa"
if [ ! -d "$artifacts_dir" ]
then
    echo "No $artifacts_dir directory, I give up"
    pwd
    exit
fi

cd "$artifacts_dir"

ls -d * \
| while read dirent
do
    if [ -d "$dirent" ]
    then
	case "$dirent"
	in
	    test-*)
		# make local short platform name link if not already there
		#
		short=`_shortname "$dirent"`
		if [ -n "$short" -a ! -L "$short" ]
		then
		    echo "$artifacts_dir/$dirent: $short symlink created"
		    $LN -s "$dirent" $short
		fi
		# remember for later
		#
		echo "$dirent" >>$tmp.dirs
	    ;;
	esac
    elif [ -L "$dirent" ]
    then
	# cull dangling symlinks
	#
	path=`realpath "$dirent" 2>/dev/null`
	if [ ! -d "$path" ]
	then
	    echo "$artifacts_dir/$dirent: dangling symlink. Removed"
	    $RM -f "$dirent"
	fi
    else
	#debug# echo ".../qa-reports/$dirent: Skipped"
	:
    fi
done

farm_dir="$HOME/Logs/by-vm"
if cd "$farm_dir"
then
    ls -d * \
    | while read dirent
    do
	if [ -L "$dirent" ]
	then
	    # cull dangling symlinks
	    #
	    path=`realpath "$dirent" 2>/dev/null`
	    if [ ! -d "$path" ]
	    then
		echo "$farm_dir/$dirent: wrong or dangling symlink. Removed"
		$RM -f "$dirent"
	    else
		case "$path"
		in

		    "$artifacts_dir"/test-*)
			;;
		    *)
			echo "$farm_dir/$dirent => $path: wrong symlink. Removed"
			$RM -f "$dirent"
			;;
		esac
	    fi
	fi
    done

    cat $tmp.dirs \
    | while read dirent
    do
	# make local short platform name link if not already there
	#
	short=`_shortname "$dirent"`
	[ -z "$short" ] && continue
	if [ ! -L "$short" ]
	then
	    echo "$farm_dir/$dirent: $short symlink created"
	    $LN -s "$artifacts_dir/$dirent" $short
	fi
    done
else
    echo "No $farm_dir directory, I give up"
    exit
fi

status=0
exit