summaryrefslogtreecommitdiff
blob: a324dc66136d53a4d8401fa210e863a32e0026c5 (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
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
#
# 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 "inst_version - Installed package version to update the slot"
	exit
}

# Find repo path
find_repo () {

	for overlay in $(portageq portdir_overlay | tr ' ' '\n'); do
		path=$(grep -H ${REPO} ${overlay}/profiles/repo_name 2>/dev/null)
		if [[ ${path} =~ "${REPO}" ]]; then
			repo_path=${path%/profiles/repo_name:${REPO}}
		fi
	done
}

# Get repo categories
read_categories () {
	while read category; do
		categories=( "${categories[@]}" "${category}" )
	done < "${repo_path}/profiles/categories"
}

# Change slot
change_slot () {
	for category in ${categories[@]}; do
		# For each category, read the list of packages
		packages=$(find "${repo_path}/${category}" -mindepth 1 -maxdepth 1 -type d)
#		echo "category ${category} has ${packages[@]}"

		# For each package, change the slot
		for dir in ${packages[@]}; do
			package=$(basename ${dir})
			files=$(find "${repo_path}/${category}/${package}/" -iname "${package}*.ebuild")

			# skip category/packages without ebuilds
			if [[ ${files} != "" ]]; then
				# for each file (there might be more than one ebuild
				for file in ${files[@]}; do

					if [[ "${INST_VERSION}" == "" ]]; then
						version=$(basename ${file})
						version=${version%.ebuild}
						version=${version%-r*}
					else
						version=${package}-${INST_VERSION}
					fi

					sed -e "s/^${OLD_SLOT}$/${NEW_SLOT}/" "${VDBDIR}/${category}/${version}/SLOT"
#					sed -i -e "s/^${OLD_SLOT}$/${NEW_SLOT}/" "${VDBDIR}/${category}/${version}/SLOT"
				done
			fi
		done
	done
}


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

SCRIPT_ARGS="$*"
REPO="${1}"
OLD_SLOT="${2}"
NEW_SLOT="${3}"
INST_VERSION="${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})"

find_repo
read_categories
change_slot

#echo "categories: ${categories[@]}"