-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathpostinstall
executable file
·137 lines (114 loc) · 3.22 KB
/
postinstall
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
#!/usr/bin/env bash
set -e
#
# NOTE: This script is run within the chroot after second stage debootstrap!
#
# Make sure we are chrooted
if [ "$(stat -c %d:%i /)" = "$(stat -c %d:%i /proc/1/root/.)" ]; then
echo "Something went wrong and we aren't in a chroot, to save your system from damage the script will fail and exit now."
exit 1;
fi
if [ "$#" -lt 8 ]; then
echo "Usage: $0 DIST ARCH LOCALE UNAME UPASS RPASS INC_REC UBOOT_DIR"
exit 1
fi
DIST=$1
ARCH=$2
LOCALE=$3
UNAME=$4
UPASS=$5
RPASS=$6
INC_REC=$7
UBOOT_DIR=$8
echo "Running postinstall script..."
# Sanitize environnement
LC_ALL=C
LANG=C
# Make dpkg/apt-get noninteractive
export DEBIAN_FRONTEND=noninteractive
export DEBCONF_NONINTERACTIVE_SEEN=true
export LC_ALL=C LANGUAGE=C LANG=C
export FLASH_KERNEL_SKIP=1
export RIB_DIST=${DIST}
if [ "${UBOOT_DIR}" = "rpi_3" ]; then
export FK_MACHINE="Raspberry Pi 3 Model B"
else
export FK_MACHINE="Raspberry Pi 2 Model B"
fi
# Prevent apt-get from starting services
echo "#!/bin/sh
exit 101
" > /usr/sbin/policy-rc.d
chmod +x /usr/sbin/policy-rc.d
# Set the locale
echo "LANG=${LOCALE}" >> /etc/default/locale
echo "locales locales/default_environment_locale select ${LOCALE}" | debconf-set-selections
echo "locales locales/locales_to_be_generated select ${LOCALE} UTF-8" | debconf-set-selections
# Finish multistrap
/var/lib/dpkg/info/base-passwd.preinst install
/var/lib/dpkg/info/dash.preinst install
dpkg --force-all --configure debconf 2>/dev/null || true
dpkg --force-all --configure mawk 2>/dev/null || true
dpkg --configure -a
# Make sure all apt keys are installed
cd /apt-keys > /dev/null
for i in *.asc; do
if [ -f $i ]; then
apt-key --keyring /etc/apt/trusted.gpg.d/${i%.*}.gpg add ${i}
fi
done
cd - > /dev/null
# Set root password
echo "root:${RPASS}" | chpasswd
# Add user $UNAME
useradd -m ${UNAME} -s /bin/bash
# Set $UNAME password
echo "${UNAME}:${UPASS}" | chpasswd
# Add $UNAME to sudo group
adduser ${UNAME} sudo || true
adduser ${UNAME} audio || true
adduser ${UNAME} video || true
adduser ${UNAME} input || true
adduser ${UNAME} tty || true
# Initialize /etc/apt/sources.list (remove multistrap from the filenames)
for i in /etc/apt/sources.list.d/*; do
mv $i $(dirname $i)/$(echo $i | cut -d"-" -f2);
done
apt-get update
APTOPTS="-y --assume-yes --force-yes"
if [ "$INC_REC" == "0" ]; then
APTOPTS="$APTOPTS --no-install-recommends";
fi
# Install extra packages
if [ -f /packages.txt ]; then
apt-get $APTOPTS install $(cat /packages.txt);
fi
# Run custom install scripts
if [ -d /postinst ]; then
echo "Running custom postinst scripts"
for i in `find /postinst -maxdepth 1 -type f -executable -not -name "*~" | sort`; do
echo " Running $i"
$i ${UNAME} ${UBOOT_DIR}
done
else
echo "No custom postinst scripts found"
fi
# Run custom install scripts for a specific distribution
if [ -d /postinst/${DIST} ]; then
echo "Running custom ${DIST} postinst scripts"
for i in `find /postinst/${DIST} -maxdepth 1 -type f -executable -not -name "*~"`; do
echo " Running $i"
$i
done
else
echo "No custom ${DIST} postinst scripts found"
fi
# Re-enable services to start
rm -f /usr/sbin/policy-rc.d
# Cleanup
echo "Running clean up"
rm -f /etc/hostname
rm -f /etc/ssh/ssh_host_*
apt-get autoclean
apt-get clean
dpkg --clear-avail