-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,049 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
pipeline { | ||
agent any | ||
stages { | ||
stage('Get image') { | ||
agent any | ||
environment { | ||
RPI_DONWLOAD_URL = 'https://downloads.raspberrypi.org/raspbian_lite_latest' | ||
RPI_ZIP_NAME = 'raspbian_lite_latest.zip' | ||
RPI_IMAGE_NAME = '2017-11-29-raspbian-stretch-lite.img' | ||
} | ||
steps { | ||
sh '$WORKSPACE/deploy/image-config.sh get_image $JENKINS_HOME $RPI_ZIP_NAME $RPI_DONWLOAD_URL $RPI_IMAGE_NAME $IMAGE_NAME' | ||
} | ||
} | ||
stage('Resize FS') { | ||
environment { | ||
SIZE = '7G' | ||
} | ||
steps { | ||
sh '$WORKSPACE/deploy/image-config.sh resize_fs $SIZE $JENKINS_HOME $IMAGE_NAME $DEV_ROOTFS' | ||
} | ||
} | ||
stage('Configure interfaces') { | ||
environment { | ||
EXECUTE_FILE = 'iface.sh' | ||
} | ||
steps { | ||
sh '$WORKSPACE/deploy/image-config.sh execute $JENKINS_HOME/$IMAGE_NAME $PREFIX_PATH $DEV_ROOTFS $DEV_BOOT $WORKSPACE/deploy/$EXECUTE_FILE' | ||
} | ||
} | ||
stage('Install Apps') { | ||
environment { | ||
EXECUTE_FILE = 'apps.sh' | ||
} | ||
steps { | ||
sh '# $WORKSPACE/deploy/image-config.sh execute $JENKINS_HOME/$IMAGE_NAME $PREFIX_PATH $DEV_ROOTFS $DEV_BOOT $WORKSPACE/deploy/$EXECUTE_FILE' | ||
} | ||
} | ||
stage('Install ROS') { | ||
environment { | ||
EXECUTE_FILE = 'ros.sh' | ||
} | ||
steps { | ||
sh '# $WORKSPACE/deploy/image-config.sh execute $JENKINS_HOME/$IMAGE_NAME $PREFIX_PATH $DEV_ROOTFS $DEV_BOOT $WORKSPACE/deploy/$EXECUTE_FILE' | ||
} | ||
} | ||
stage('Publish image') { | ||
environment { | ||
CONFIG_FILE = 'coex-ci.conf' | ||
} | ||
steps { | ||
sh '$WORKSPACE/deploy/image-config.sh publish_image $JENKINS_HOME $IMAGE_NAME $WORKSPACE $CONFIG_FILE $RELEASE_ID $RELEASE_BODY' | ||
} | ||
} | ||
} | ||
environment { | ||
PREFIX_PATH = '/mnt' | ||
DEV_BOOT = '/dev/disk/by-uuid/CDD4-B453' | ||
DEV_ROOTFS = '/dev/disk/by-uuid/72bfc10d-73ec-4d9e-a54a-1cc507ee7ed2' | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/bin/bash | ||
|
||
################################################################################################################################## | ||
# Установка необходимых программ | ||
################################################################################################################################## | ||
|
||
|
||
echo -e "\033[0;31m\033[1m$(date) | #1 apt update && apt upgrade\033[0m\033[0m" | ||
|
||
# install bootstrap tools | ||
apt-get update | ||
# && apt upgrade -y | ||
|
||
|
||
|
||
echo -e "\033[0;31m\033[1m$(date) | #2 Install programs\033[0m\033[0m" | ||
|
||
apt-get install --no-install-recommends -y \ | ||
ipython \ | ||
screen \ | ||
byobu \ | ||
nmap \ | ||
lsof \ | ||
python-pip \ | ||
git \ | ||
isc-dhcp-server \ | ||
tmux | ||
|
||
|
||
|
||
|
||
|
||
echo -e "\033[0;31m\033[1m$(date) | #3 Write to /etc/wpa_supplicant/wpa_supplicant.conf\033[0m\033[0m" | ||
|
||
echo " | ||
network={ | ||
ssid=\"CLEVER\" | ||
mode=2 | ||
key_mgmt=WPA-PSK | ||
psk=\"cleverwifi\" | ||
frequency=2437 | ||
}" >> /etc/wpa_supplicant/wpa_supplicant.conf | ||
|
||
|
||
|
||
|
||
|
||
echo -e "\033[0;31m\033[1m$(date) | #4 Write STATIC to /etc/dhcpcd.conf\033[0m\033[0m" | ||
|
||
echo " | ||
interface wlan0 | ||
static ip_address=192.168.11.1/24" >> /etc/dhcpcd.conf | ||
|
||
|
||
|
||
|
||
echo -e "\033[0;31m\033[1m$(date) | #5 Write iface to /etc/default/isc-dhcp-server\033[0m\033[0m" | ||
|
||
# https://www.shellhacks.com/ru/sed-find-replace-string-in-file/ | ||
sed -i 's/INTERFACESv4=\"\"/INTERFACESv4=\"wlan0\"/' /etc/default/isc-dhcp-server | ||
|
||
|
||
echo -e "\033[0;31m\033[1m$(date) | #6 Write dhcp declaration subnet to /etc/dhcp/dhcpd.conf\033[0m\033[0m" | ||
|
||
|
||
echo "subnet 192.168.11.0 netmask 255.255.255.0 { | ||
range 192.168.11.11 192.168.11.254; | ||
#option domain-name-servers 8.8.8.8; | ||
#option domain-name "rpi.local"; | ||
option routers 192.168.11.1; | ||
option broadcast-address 192.168.11.255; | ||
default-lease-time 600; | ||
max-lease-time 7200; | ||
}" >> /etc/dhcp/dhcpd.conf | ||
|
||
|
||
|
||
echo -e "\033[0;31m\033[1m$(date) | #7 Write start script for dhcpd to /etc/network/if-up.d/isc-dhcp-server\033[0m\033[0m" | ||
|
||
echo "#!/bin/sh | ||
if [ \"\$IFACE\" = \"--all\" ]; | ||
then sleep 10 && systemctl start isc-dhcp-server.service & | ||
fi | ||
" > /etc/network/if-up.d/isc-dhcp-server \ | ||
&& chmod +x /etc/network/if-up.d/isc-dhcp-server | ||
|
||
|
||
|
||
echo -e "\033[0;31m\033[1m$(date) | #8 Write magic script for rename SSID to /etc/rc.local\033[0m\033[0m" | ||
|
||
RENAME_SSID="sudo sed -i.OLD \"s/CLEVER/CLEVER-\$(head -c 100 /dev/urandom | xxd -ps -c 100 | sed -e 's/[^0-9]//g' | cut -c 1-4)/g\" /etc/wpa_supplicant/wpa_supplicant.conf && sudo sed -i '/sudo sed/d' /etc/rc.local && sudo reboot" | ||
|
||
|
||
sed -i "19a$RENAME_SSID" /etc/rc.local | ||
|
||
|
||
|
||
echo -e "\033[0;31m\033[1m$(date) | #9 End of install programs\033[0m\033[0m" | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python | ||
|
||
# | ||
# Simple github release body-editor | ||
# Smirnov Artem @urpylka | ||
# | ||
# Use: | ||
# python git_release.py CONFIG_FILE RELEASE_ID RELEASE_BODY | ||
# | ||
|
||
|
||
from ConfigParser import SafeConfigParser | ||
import requests, sys, urllib | ||
|
||
def json_wrapper(image_name, image_link, image_size, old_text): | ||
old_text = urllib.unquote_plus(old_text) | ||
buffer = "### Download\n* [" + image_name + ".zip](" + image_link + ") (" + image_size + ")\n\n" + old_text | ||
js = {} | ||
js["body"] = buffer | ||
return js | ||
|
||
|
||
def main(): | ||
|
||
cfgParser = SafeConfigParser() | ||
cfgParser.read(sys.argv[1]) | ||
|
||
js = json_wrapper(sys.argv[4], sys.argv[5], sys.argv[6], sys.argv[3]) | ||
|
||
r = requests.patch(cfgParser.get('github','url') + sys.argv[2], json=js, auth=(cfgParser.get('github','login'), cfgParser.get('github','password'))) | ||
|
||
if r.status_code == 200: | ||
print("Message has been successfully added!") | ||
else: | ||
return 1 | ||
|
||
if __name__ == '__main__': | ||
main() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#!/bin/bash | ||
|
||
################################################################################################################################## | ||
# Настройка интерфейсов | ||
################################################################################################################################## | ||
|
||
# вот так все в принципе должно включиться | ||
# /usr/bin/raspi-config nonint do_i2c 0 | ||
# /usr/bin/raspi-config nonint do_spi 0 | ||
# /usr/bin/raspi-config nonint do_camera 0 | ||
# /usr/bin/raspi-config nonint do_rgpio 0 | ||
# /usr/bin/raspi-config nonint do_ssh 0 | ||
|
||
# по идеи эти настройки должны проводиться до по другому как сделано в prepare_image.sh | ||
|
||
set_config_var() { | ||
lua - "$1" "$2" "$3" <<EOF > "$3.bak" | ||
local key=assert(arg[1]) | ||
local value=assert(arg[2]) | ||
local fn=assert(arg[3]) | ||
local file=assert(io.open(fn)) | ||
local made_change=false | ||
for line in file:lines() do | ||
if line:match("^#?%s*"..key.."=.*$") then | ||
line=key.."="..value | ||
made_change=true | ||
end | ||
print(line) | ||
end | ||
if not made_change then | ||
print(key.."="..value) | ||
end | ||
EOF | ||
mv "$3.bak" "$3" | ||
} | ||
|
||
BLACKLIST=/etc/modprobe.d/raspi-blacklist.conf | ||
CONFIG=/boot/config.txt | ||
|
||
# 2. Изменить необходимые настройки | ||
|
||
# 2.1. Включить sshd | ||
echo -e "\033[0;31m\033[1m$(date) | #11 Turn on sshd\033[0m\033[0m" | ||
touch /boot/ssh | ||
|
||
# 2.2. Включить GPIO | ||
# Включено по умолчанию | ||
|
||
# 2.3. Включить I2C | ||
echo -e "\033[0;31m\033[1m$(date) | #12 Turn on I2C\033[0m\033[0m" | ||
|
||
set_config_var dtparam=i2c_arm on $CONFIG && | ||
if ! [ -e $BLACKLIST ]; then | ||
touch $BLACKLIST | ||
fi | ||
sed $BLACKLIST -i -e "s/^\(blacklist[[:space:]]*i2c[-_]bcm2708\)/#\1/" | ||
sed /etc/modules -i -e "s/^#[[:space:]]*\(i2c[-_]dev\)/\1/" | ||
if ! grep -q "^i2c[-_]dev" /etc/modules; then | ||
printf "i2c-dev\n" >> /etc/modules | ||
fi | ||
|
||
# 2.4. Включить SPI | ||
echo -e "\033[0;31m\033[1m$(date) | #13 Turn on SPI\033[0m\033[0m" | ||
|
||
set_config_var dtparam=spi on $CONFIG && | ||
if ! [ -e $BLACKLIST ]; then | ||
touch $BLACKLIST | ||
fi | ||
sed $BLACKLIST -i -e "s/^\(blacklist[[:space:]]*spi[-_]bcm2708\)/#\1/" | ||
|
||
# 2.5. Включить raspicam | ||
echo -e "\033[0;31m\033[1m$(date) | #14 Turn on raspicam\033[0m\033[0m" | ||
|
||
get_config_var() { | ||
lua - "$1" "$2" <<EOF | ||
local key=assert(arg[1]) | ||
local fn=assert(arg[2]) | ||
local file=assert(io.open(fn)) | ||
local found=false | ||
for line in file:lines() do | ||
local val = line:match("^%s*"..key.."=(.*)$") | ||
if (val ~= nil) then | ||
print(val) | ||
found=true | ||
break | ||
end | ||
end | ||
if not found then | ||
print(0) | ||
end | ||
EOF | ||
} | ||
|
||
# тут уже немного иначе, но по сути одно и тоже | ||
# https://github.com/RPi-Distro/raspi-config/blob/master/raspi-config#L1136 | ||
# $1 is 0 to disable camera, 1 to enable it | ||
set_camera() { | ||
# Stop if /boot is not a mountpoint | ||
#if ! mountpoint -q /boot; then | ||
# return 1 | ||
#fi | ||
|
||
[ -e $CONFIG ] || touch $CONFIG | ||
|
||
if [ "$1" -eq 0 ]; then # disable camera | ||
set_config_var start_x 0 $CONFIG | ||
sed $CONFIG -i -e "s/^startx/#startx/" | ||
sed $CONFIG -i -e "s/^start_file/#start_file/" | ||
sed $CONFIG -i -e "s/^fixup_file/#fixup_file/" | ||
else # enable camera | ||
set_config_var start_x 1 $CONFIG | ||
CUR_GPU_MEM=$(get_config_var gpu_mem $CONFIG) | ||
if [ -z "$CUR_GPU_MEM" ] || [ "$CUR_GPU_MEM" -lt 128 ]; then | ||
set_config_var gpu_mem 128 $CONFIG | ||
fi | ||
sed $CONFIG -i -e "s/^startx/#startx/" | ||
sed $CONFIG -i -e "s/^fixup_file/#fixup_file/" | ||
fi | ||
} | ||
|
||
if [ ! -e /boot/start_x.elf ]; | ||
then echo "Your firmware appears to be out of date (no start_x.elf). Please update" | ||
else set_camera 1 | ||
fi | ||
|
||
# Включение V4L драйвера http://robocraft.ru/blog/electronics/3158.html | ||
#echo "bcm2835-v4l2" >> /etc/modules | ||
if ! grep -q "^bcm2835-v4l2" /etc/modules; then | ||
printf "bcm2835-v4l2\n" >> /etc/modules | ||
fi | ||
|
||
# 2.6. Настроить AP wifi | ||
# 2.7. Настроить сеть на wlan | ||
# 2.8. Настроить DHCPd на wlan | ||
|
||
|
||
echo -e "\033[0;31m\033[1m$(date) | #15 End of configuring interfaces\033[0m\033[0m" |
Oops, something went wrong.