summaryrefslogtreecommitdiff
blob: 02514c9030f402cf5792d47cc280a8d458b95368 (plain)
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
#
# change_slot script
#
# 2008/10/05
# Jorge Manuel B. S. Vicetto (jmbsvicetto@gentoo.org)


###############
# Constants
###############
VDBDIR=$(portageq vdb_path)


###############
# Functions
###############

# Show options screen
show_options () {

# Present options
	echo "Usage: $0 repo old_slot new_slot"
	echo "repo - The repo name as specified in ${repo}/profiles/repo_name"
	echo "old_slot - The slot to be replaced"
	echo "new_slot - The new slot to use"
	echo "change - really change? [Y] to apply"
	exit
}

# Change slot
change_slot () {
	sed -e "s/^${OLD_SLOT}$/${NEW_SLOT}/" "${package}/SLOT"

	if [[ ${CHANGE} == "Y" ]]; then
		sed -i -e "s/^${OLD_SLOT}$/${NEW_SLOT}/" "${package}/SLOT"
	fi
}

# Run the vdb
run_vdb() {

	# Get categories from the VDB
	categories=$(find "${VDBDIR}" -mindepth 1 -maxdepth 1 -type d)
	for category in ${categories[@]}; do

		# For each category
		packages=$(find "${category}" -mindepth 1 -maxdepth 1 -type d)
		for package in ${packages[@]}; do

			# If package was installed from the repo
			name=$(cat ${package}/repository)
			if [[ "${name}" == "${REPO}" ]]; then
				echo "package: ${package} - matches ${REPO}"
				change_slot
			fi
		done		
	done
}


###############
# Get options and commands
###############
[[ -z "$*" ]] && show_options

SCRIPT_ARGS="$*"
REPO="${1}"
OLD_SLOT="${2}"
NEW_SLOT="${3}"
CHANGE="${4}"

if ([[ -z "${REPO}" ]] || [[ -z "${OLD_SLOT}" ]] || [[ -z "${NEW_SLOT}" ]]); then
	show_options
fi

echo "You've asked to update all packages from repo ${REPO} in ${VDBDIR} by changing the old_slot (${OLD_SLOT}) to new_slot (${NEW_SLOT})"

run_vdb