Created
March 25, 2014 23:00
-
-
Save initbrain/9773373 to your computer and use it in GitHub Desktop.
Cubieboard A10 - SD Card installation script - Debian 7.4 - Linux 3.4.79-r0-s-rm1+ "server" kernel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Cubieboard A10 - SD Card installation script | |
# Debian 7.4 - Linux 3.4.79-r0-s-rm1+ "server" kernel | |
# Julien Deudon (initbrain) - 25/03/2014 | |
# Tested on Debian 7.4 | |
# Required: | |
# apt-get install build-essential git udev coreutils bzip2 curl | |
# make (apt-get install build-essential) | |
# git (apt-get install git) | |
# udevadm (apt-get install udev) | |
# md5sum (apt-get install coreutils) | |
# mkfs (does not seem to be necessary, apt-get install util-linux) | |
# bzip2 (apt-get install bzip2) | |
# curl (apt-get install curl) | |
# Tips: | |
# If the SD Card is not detected, deplug it, replug it and relaunch the script | |
# (udevadm does not seem to properly manage the creation of new partition) | |
# If you want to change the default screen type / resolution, edit script.bin (via bin2fex/fex2bin) | |
# (see http://linux-sunxi.org/Fex_Guide#disp_init_configuration ) | |
# If you want to disable leds, edit script.bin (via bin2fex/fex2bin) | |
# (see http://linux-sunxi.org/Fex_Guide#led_configuration ) | |
SPEAKSYNTH=1 # let's the script speak at important steps (0 to desactivate, apt-get install espeak) | |
if [ ! which espeak &>/dev/null ] | |
else | |
SPEAKSYNTH=0 | |
fi | |
# Make sure only root can run our script | |
if [[ $EUID -ne 0 ]] #if [ $(id -u) -ne 0 ] | |
then | |
echo "This script must be run as root" 1>&2 | |
exit 1 | |
fi | |
echo -e "\nCubieboard A10 - SD Card installation script" | |
echo -e "Debian 7.4 - Linux 3.4.79-r0-s-rm1+ \"server\" kernel\n" | |
# Ask standard user account | |
echo "[+] Type your standard user account, followed by [ENTER]:" | |
read MYUSER | |
while [ $(grep -c "^$MYUSER:" /etc/passwd) -eq 0 ] | |
do | |
echo "[!] This user does not exist, please retype it:" | |
read MYUSER | |
done | |
echo -e "[i] Standard user account: $MYUSER\n" | |
# Get a list of present mediums | |
DEVICES=() | |
DEVICEPATHS=$(ls /dev/sd?) | |
eval set $DEVICEPATHS | |
for DEVICEPATH in "$@" | |
do | |
if [ $(udevadm info --query=all --name=$DEVICEPATH | grep -c ID_PART_TABLE_TYPE) -eq 1 ] | |
then | |
DEVICES+=($DEVICEPATH) | |
fi | |
done | |
# Select SD Card | |
echo "[+] Select your SD Card (be careful it will be formatted):" | |
DEVICES+=("exit") | |
select OPT in "${DEVICES[@]}" | |
do | |
if (for e in ${DEVICES[@]}; do [[ "$e" == "$OPT" ]] && exit 0; done) | |
then | |
if [ "$OPT" == "exit" ] | |
then | |
echo -e "[!] Installation aborted\n" | |
exit | |
else | |
DESTINATION=$OPT | |
echo -e "[i] SD Card: $DESTINATION\n" | |
break | |
fi | |
else | |
echo "[!] Wrong input, please make a new choice:" | |
fi | |
done | |
# Getting started | |
echo "[+] Getting started" | |
cd /home/$MYUSER | |
if [ ! -d "Cubieboard" ] | |
then | |
su -l $MYUSER -p -c 'mkdir Cubieboard' | |
fi | |
cd Cubieboard | |
# Download Debian server image | |
if [ -f a10-debian-server-2gb.2014-02-17.img.bz2 ] | |
then | |
echo "[+] Debian server image already downloaded" | |
MD5SUM=$(md5sum a10-debian-server-2gb.2014-02-17.img.bz2 | awk '{print $1}') | |
if [ "$MD5SUM" == "3896bead977acef7c94c538b59cb463d" ] | |
then | |
echo "[+] Checksum OK" | |
else | |
echo "[+] MD5 sum mismatch" | |
rm a10-debian-server-2gb.2014-02-17.img.bz2 | |
fi | |
fi | |
if [ ! -f a10-debian-server-2gb.2014-02-17.img.bz2 ] | |
then | |
echo "[+] Downloading Debian server image" | |
#su --preserve-environment -l $MYUSER -p -c 'wget https://romanrm.net/dl/a10/debian/a10-debian-server-2gb.2014-02-17.img.bz2' | |
su --preserve-environment -l $MYUSER -p -c 'curl -O https://romanrm.net/dl/a10/debian/a10-debian-server-2gb.2014-02-17.img.bz2' | |
fi | |
# Unmounting SD Card | |
if [ $(mount | grep -c $DESTINATION) -ne 0 ] | |
then | |
echo "[+] Unmounting SD Card" | |
umount $DESTINATION | |
fi | |
# SD Card FAT32 formatting (does not seem to be necessary) | |
#echo "[+] SD Card FAT32 formatting" | |
#mkfs.vfat -F 32 -n cubieboard $DESTINATION &>/dev/null | |
# Extractiong Debian server image to SD Cardf | |
echo "[+] Extractiong Debian server image to SD Card" | |
bzip2 -dc a10-debian-server-2gb.2014-02-17.img.bz2 > $DESTINATION | |
# Force disk writes (modified blocks), update the superblock | |
echo "[+] Force disk writes (modified blocks), update the superblock" | |
sync | |
# Installation of sunxi-tools | |
echo "[+] Installation of sunxi-tools" | |
if [ ! -d "sunxi-tools" ] | |
then | |
su --preserve-environment -l $MYUSER -c "git clone https://github.com/linux-sunxi/sunxi-tools" &>/dev/null | |
cd sunxi-tools/ | |
su --preserve-environment -l $MYUSER -c 'make bin2fex' &>/dev/null | |
su --preserve-environment -l $MYUSER -c 'make fex2bin' &>/dev/null | |
cd .. | |
fi | |
# Mounting SD Card boot partition | |
echo "[+] Mounting SD Card boot partition" | |
mkdir /tmp/cubieboard_a10_boot | |
mount /dev/sdg1 /tmp/cubieboard_a10_boot | |
# Generating new script.bin | |
#cp /tmp/cubieboard_a10_boot/script.bin ./script.bin.orig | |
#./sunxi-tools/bin2fex script.bin.orig cubieboard.fex | |
echo "[+] Generating new script.bin for Cubieboard A10" | |
if [ ! -f cubieboard.fex ] | |
then | |
echo "[+] Downloading cubieboard.fex" | |
su --preserve-environment -l $MYUSER -p -c 'curl -O https://raw.githubusercontent.com/linux-sunxi/sunxi-boards/master/sys_config/a10/cubieboard.fex' &>/dev/null | |
else | |
echo "[+] Using current cubieboard.fex" | |
fi | |
# Pause installation to edit cubieboard.fex, autoresume if no key are pressed in the next 10sec | |
if [ $SPEAKSYNTH -eq 1 ] | |
then | |
espeak "press a key to edit" &>/dev/null & | |
fi | |
read -t 10 -n1 -r -p "[+] Press any key in the next 10sec to edit the script.bin content" | |
if [ $? -eq 0 ] | |
then | |
echo -e "\n[i] A key was pressed\n" | |
vi cubieboard.fex | |
else | |
echo -e "\n[i] No key was pressed\n" | |
fi | |
# Copying new script.bin into boot partition | |
echo "[+] Copying new script.bin into boot partition" | |
su --preserve-environment -l $MYUSER -p -c './sunxi-tools/fex2bin cubieboard.fex script.bin.custom' &>/dev/null | |
cp ./script.bin.custom /tmp/cubieboard_a10_boot/script.bin | |
# Force disk writes (modified blocks), update the superblock | |
echo "[+] Force disk writes (modified blocks), update the superblock" | |
sync | |
# Unmounting SD Card boot partition | |
echo "[+] Unmounting SD Card boot partition" | |
umount /dev/sdg1 | |
rmdir /tmp/cubieboard_a10_boot | |
# End | |
if [ $SPEAKSYNTH -eq 1 ] | |
then | |
espeak "installation complete" &>/dev/null & | |
fi | |
echo -e "[+] Installation complete\n" | |
echo """[i] Now plug the SD Card in the Cubieboard and turn it on | |
[i] Find out which IP your device got | |
If you didn't set up a static configuration, check your DHCP server logs | |
or a list of current leases, to see which IP the newly-booted device has obtained | |
You can also use nmap to found it, in my case: nmap 192.168.1.1-254 | |
(apt-get install nmap) | |
It take approximately 30sec to boot. | |
[i] Using the IP you found, login via SSH to it | |
Default user/password are: root/password | |
[i] Some reminders/ideas on what you might want to do next: | |
- Regenerate SSH host keys | |
- Change the root password with: | |
passwd | |
- Update package index file with: | |
aptitude update | |
- Install the latest versions of all packages on the system with: | |
aptitude dist-upgrade -y | |
- Set your locale with: | |
dpkg-reconfigure locales | |
- Select your timezone with: | |
dpkg-reconfigure tzdata | |
- Install VIM with: | |
aptitude install -y vim | |
- Change the message displayed after login, with: | |
echo -en "" > /etc/motd | |
- Add a new user with: | |
adduser your_username | |
- Disable remote SSH login as root with: | |
sed -i 's/^PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config; service ssh restart | |
- Change the default SSH port number with: | |
sed -i 's/^Port .*/Port 2222/g' /etc/ssh/sshd_config; service ssh restart | |
etc. | |
[i] To deploy a Flask application: | |
https://www.digitalocean.com/community/articles/how-to-deploy-a-flask-application-on-an-ubuntu-vps | |
https://beagle.whoi.edu/redmine/projects/ibt/wiki/Deploying_Flask_Apps_with_Apache_and_Mod_WSGI | |
aptitude install -y libapache2-mod-wsgi python-pip | |
pip install Flask | |
put your project files (/var/www/your_flask_app/ + /etc/apache2/sites-available/your_flask_app) | |
chown -R www-data:www-data /var/www/ | |
rm /etc/apache2/sites-available/default* | |
rm /etc/apache2/sites-enabled/000-default | |
a2ensite your_flask_app | |
service apache2 reload | |
service apache2 start | |
[i] Big thanks to Roman, also known as \"rm\" or \"RM\" | |
especially for this page https://romanrm.net/a10/debian | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment