forked from gsanhueza/ArchISOMaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_tools.sh
More file actions
91 lines (73 loc) · 2.09 KB
/
custom_tools.sh
File metadata and controls
91 lines (73 loc) · 2.09 KB
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
#!/bin/bash
script_path=$(readlink -f ${0%/*})
# Custom variables
work_dir="work"
out_dir="out"
temp_mnt="${script_path}/TEMPMNT"
custom_pkg_dir="${script_path}/airootfs/root/pkg"
UPDATECACHE=1
# Helper function to run make_*() only one time per architecture.
run_once() {
if [[ ! -e ${work_dir}/build.${1} ]]; then
$1
touch ${work_dir}/build.${1}
fi
}
# Create needed folders for make_local_repo
make_folder() {
echo "Creating temporal root folder..."
# Make root directory
if [[ ! -e ${temp_mnt} ]]; then
mkdir -p ${temp_mnt}
echo "Creating temporal install root at ${temp_mnt}"
mkdir -m 0755 -p "${temp_mnt}"/var/{cache/pacman/pkg,lib/pacman,log} ${temp_mnt}/{dev,run,etc}
mkdir -m 1777 -p "${temp_mnt}"/tmp
mkdir -m 0555 -p "${temp_mnt}"/{sys,proc}
fi
# Make repo folder
if [[ ! -e ${custom_pkg_dir} ]]; then
mkdir -p ${custom_pkg_dir}
fi
}
# Pull packages from Internet
# See packages.sh
make_download() {
echo "Downloading packages..."
source "detect_packages.sh"
pacman -Syw --root ${temp_mnt} --cachedir ${custom_pkg_dir} --noconfirm $ALL_PACKAGES
}
# Create Pacman DB
make_database() {
echo "Creating package database..."
n=0
# If the command didn't run correctly, re-run. It solves the file-not-found error. Go figure.
# We'll re-run the command up to 5 times.
until [ $n -ge 5 ]
do
repo-add -R -n ${custom_pkg_dir}/custom.db.tar.gz ${custom_pkg_dir}/*pkg.tar.{xz,zst} && break # If command ran ok, don't re-run
n=$[$n+1]
sleep 1
done
}
# Make local pkg database and repo only if needed
make_local_repo() {
echo "Creating local repo..."
run_once make_folder
if (( UPDATECACHE )); then
run_once make_download
run_once make_database
fi
sync
echo ""
echo "Local repo is ready!"
}
# Cleaning duties
wrap_up() {
echo "Wrapping up..."
OWNER=${SUDO_USER:-$USER}
rm ${work_dir} -rf
rm ${temp_mnt} -rf
chown $OWNER:$OWNER ${out_dir}/*.iso -v
mv ${out_dir}/* .. -v
rm ${out_dir} -rf
}