-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean
executable file
·153 lines (117 loc) · 3.62 KB
/
clean
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
148
149
150
151
152
153
#/usr/bin/env sh
# This file is part of reproducible-rust. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/reproducible-rust/master/COPYRIGHT. No part of reproducible-rust, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
# Copyright © 2021 The developers of reproducible-rust. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/reproducible-rust/master/COPYRIGHT.
set -e
set -u
set -f
_program_path_find()
{
if [ "${0%/*}" = "$0" ]; then
# We've been invoked by the interpreter as, say, bash program
if [ -r "$0" ]; then
pwd -P
# Clutching at straws; probably run via a download, anonymous script, etc, weird execve, etc
else
printf '\n'
fi
else
# We've been invoked with a relative or absolute path (also when invoked via PATH in a shell)
_program_path_find_parentPath()
{
parentPath="${scriptPath%/*}"
if [ -z "$parentPath" ]; then
parentPath='/'
fi
cd "$parentPath" 1>/dev/null
}
# pdksh / mksh have problems with unsetting a variable that was never set...
if [ "${CDPATH+set}" = 'set' ]; then
unset CDPATH
fi
if command -v realpath 1>/dev/null 2>/dev/null; then
(
scriptPath="$(realpath "$0")"
_program_path_find_parentPath
pwd -P
)
elif command -v readlink 1>/dev/null 2>/dev/null; then
(
local recursionDepth=0
_program_path_resolve_symlinks_recursively()
{
local unresolvedPath="$1"
recursionDepth=$((recursionDepth + 1))
if [ $recursionDepth -gt 10 ]; then
printf '%s\n' 'Recursion to depths greater than 10 is not allowed when resolving links.'
return 1
fi
local potentialLinkDestination="$(readlink -- "$unresolvedPath")"
if [ -z "$potentialLinkDestination" ]; then
scriptPath="$unresolvedPath"
return 0
fi
local linkDestination="$potentialLinkDestination"
local parentFolderPath="${unresolvedPath%/*}"
if [ "$parentFolderPath" = "$unresolvedPath" ]; then
_program_path_resolve_symlinks_recursively "$linkDestination"
else
case "$linkDestination" in
/*)
_program_path_resolve_symlinks_recursively "$linkDestination"
;;
*)
_program_path_resolve_symlinks_recursively "$parentFolderPath"/"$linkDestination"
;;
esac
fi
}
scriptPath="$0"
_program_path_resolve_symlinks_recursively "$scriptPath"
_program_path_find_parentPath
pwd -P
)
else
# This approach will fail in corner cases where the script itself is a symlink in a path not parallel with the concrete script
(
scriptPath="$0"
_program_path_find_parentPath
pwd -P
)
fi
fi
}
cd "$(_program_path_find)" 1>/dev/null 2>/dev/null
. functions/common.sh
. functions/common.outside-docker.sh
guard_arguments()
{
case $# in
1)
case "$1" in
-h|-help|--help|help)
exit_help_message "Removes the contents of the output/ and temporary/ folders then prunes containers and images to remove all but latest"
;;
*)
:
;;
esac
;;
*)
:
;;
esac
}
depends docker
main()
{
guard_arguments "$@"
local output_folder_path
local source_folder_path
local temporary_folder_path
set_paths
clean_folder "$output_folder_path"
clean_folder "$temporary_folder_path"
docker container prune --force 1>/dev/null
docker image prune --force 1>/dev/null
}
main "$@"