[enh] Be able to run ./install_yunohost on raspbian

This commit is contained in:
ljf 2017-01-11 22:58:07 +01:00
parent 8457d79dec
commit 2ee7d57f21

View file

@ -74,6 +74,20 @@ ensure_root() {
return 0
}
ensure_pi_logout() {
who | grep pi > /dev/null && return 1
return 0
}
is_raspbian() {
# On Raspbian image lsb_release is available
if [[ "$(lsb_release -i -s 2> /dev/null)" != "Raspbian" ]] ;
then
return 1
fi
return 0
}
apt_get_wrapper() {
if [[ "$AUTOMODE" == "0" ]] ;
then
@ -87,11 +101,27 @@ apt_get_wrapper() {
}
upgrade_system() {
apt_get_wrapper update \
if is_raspbian ; then
# https://github.com/RPi-Distro/raspberrypi-sys-mods/issues/6#issuecomment-254902333
sed -i 's/frontend=pager/frontend=text/' /etc/apt/listchanges.conf
fi
apt_get_wrapper update \
|| return 1
apt_get_wrapper -y dist-upgrade \
apt_get_wrapper -y dist-upgrade \
|| return 2
if is_raspbian ; then
apt_get_wrapper -o Dpkg::Options::="--force-confold" \
-y --force-yes install rpi-update \
|| return 3
rpi-update \
|| return 4
sed -i 's/frontend=text/frontend=pager/' /etc/apt/listchanges.conf
fi
}
installscript_dependencies() {
@ -107,6 +137,19 @@ installscript_dependencies() {
-y --force-yes install \
$DEPENDENCIES \
|| return 1
if is_raspbian ; then
DEPENDENCIES="ssl-cert lua-event lua-expat lua-socket lua-sec lua-filesystem"
apt_get_wrapper -o Dpkg::Options::="--force-confold" \
-y --force-yes install \
$DEPENDENCIES \
|| return 1
wget -q https://raw.githubusercontent.com/likeitneverwentaway/rpi_buildbot/master/metronome_3.7.9+33b7572-1_armhf.deb
sha256sum -c <<<"d19c6b08afb8674d1257dc3349a60e88218c4c01133c53c1fdcb02e86b415a40 metronome_3.7.9+33b7572-1_armhf.deb"
dpkg -i metronome_3.7.9+33b7572-1_armhf.deb
apt-mark hold metronome
fi
}
create_custom_config() {
@ -160,7 +203,7 @@ setup_package_source() {
fi
# Add YunoHost repository key to the keyring
wget -O- http://repo.yunohost.org/yunohost.asc -q | apt-key add - -qq > /dev/null
wget -O- https://repo.yunohost.org/yunohost.asc -q | apt-key add - -qq > /dev/null
}
apt_update() {
@ -254,6 +297,56 @@ restart_services() {
return 0
}
del_user_pi() {
deluser --remove-all-files pi
}
change_hostname() {
sed -i 's/raspberrypi/yunohost/g' /etc/hosts
sed -i 's/raspberrypi/yunohost/g' /etc/hostname
}
setup_firstboot() {
cat > /etc/init.d/yunohost-firstboot << EOF
#!/bin/sh
### BEGIN INIT INFO
# Provides: expand rootfs and Generates new ssh host keys on first boot
# Required-Start: \$remote_fs \$syslog
# Required-Stop: \$remote_fs \$syslog
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Generates new ssh host keys on first boot
# Description: Generatesapt-get --purge clean new ssh host keys on $
### END INIT INFO
echo "Expanding rootfs ..."
raspi-config --expand-rootfs
echo "Removing myself ..."
insserv -r /etc/init.d/yunohost-firstboot
rm -f /etc/init.d/yunohost-firstboot
rm /etc/yunohost/firstboot
echo "Rebooting ..."
reboot
EOF
chmod a+x /etc/init.d/yunohost-firstboot
insserv /etc/init.d/yunohost-firstboot
touch /etc/yunohost/firstboot
}
clean_image() {
echo "Generating new ssh keys ..."
# Delete SSH keys
rm -f /etc/ssh/ssh_host_*
yes | ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
yes | ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
yes | ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa -b 521
echo "Deleting logs ..."
find /var/log -type f -exec rm {} \;
echo "Purging apt ..."
apt-get --purge clean
}
post_install() {
# No postinstall in auto mode
[[ "$AUTOMODE" == "1" ]] && return 0
@ -322,7 +415,8 @@ set -u
AUTOMODE=0
DISTRIB=stable
while getopts ":ad:h" option; do
BUILD_IMAGE=0
while getopts ":aid:h" option; do
case $option in
a)
AUTOMODE=1
@ -331,6 +425,10 @@ while getopts ":ad:h" option; do
d)
DISTRIB=$OPTARG
;;
i)
# This hidden option will allow to build generic image for Rpi/Olimex
BUILD_IMAGE=1
;;
h)
usage
exit 0
@ -350,6 +448,12 @@ if ! step ensure_root ; then
die "This script must be run as root" 1
fi
if is_raspbian ; then
if ! step ensure_pi_logout ; then
die "The user pi should be logged out" 14
fi
fi
if ! step upgrade_system ; then
die "Unable to update the system" 2
fi
@ -394,10 +498,36 @@ if ! step restart_services ; then
die "Error caught during services restart" 12
fi
if ! step post_install ; then
die "Post-installation failed" 13
if is_raspbian ; then
if ! step del_user_pi ; then
die "Unable to delete user pi" 15
fi
if ! step change_hostname ; then
die "Unable to change hostname" 16
fi
if ! step setup_firstboot ; then
die "Unable to setup firstboot" 17
fi
fi
if [[ "$BUILD_IMAGE" == "1" ]] ; then
if ! step clean_image ; then
die "Unable to clean image" 18
fi
fi
if ! step post_install ; then
die "Post-installation failed" 13
fi
# Success !
success
if is_raspbian ; then
reboot
fi
exit 0