Skip to content

Commit 9b93d8c

Browse files
committed
Merge pull request #33 from fangohr/FEAT-030
FEAT-030: Add build version to the virtual micromagnetics wallpaper
2 parents 8e6039a + 5b92411 commit 9b93d8c

File tree

5 files changed

+136
-64
lines changed

5 files changed

+136
-64
lines changed

jobs/hook.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@
1313
name={{ artefact_dir }}
1414
state=directory
1515

16-
- name: Get current repository version.
17-
command: git rev-parse HEAD
18-
register: current_revision
19-
16+
# current_version is defined in the create_VM playbook.
2017
- name: Define the name used for output files, sans extension.
2118
set_fact:
22-
output_name: "{{ vm_name }}-{{ current_revision.stdout }}"
19+
output_name: "{{ vm_name }}-{{ current_version.stdout }}"
2320

2421
# We can skip the creation of the zipped VHD if it already exists (for
2522
# idempotency). Hence we check for the ZIP here and, if it is found, other

roles/create_VM/tasks/main.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@
4545
option=roles_path
4646
value={{ lookup('pipe','pwd') }}/../..
4747

48+
- name: Obtain the current tag, (or version if untagged) of this repository.
49+
shell: |
50+
TAG=$(git name-rev --tags --name-only HEAD)
51+
if [ "$(echo $TAG | tr -d [:space:])" == "undefined" ]; then
52+
git rev-parse --short HEAD
53+
else
54+
echo $TAG
55+
fi
56+
args:
57+
chdir: "{{ vm_dir }}"
58+
executable: /bin/bash
59+
register: current_version
60+
61+
- name: Store this version or tag in a file so that the virtual machine can access it.
62+
lineinfile:
63+
dest={{ vm_dir }}/repository_version
64+
create=yes
65+
state=present
66+
regexp="^[0-9a-zA-Z]*"
67+
line={{ current_version.stdout }}
68+
4869
- name: Start the virtual machine. Vagrant may attempt to install VirtualBox Guest Additions here.
4970
shell: vagrant up --no-provision > {{ vm_name }}.log
5071
chdir={{ vm_dir }}

roles/xserver/tasks/main.yml

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,5 @@
11
---
22
# This Ansible playbook defines an environment in which X works for user
33
# friendliness.
4-
5-
# Important to install the packages in this order, otherwise icons will not
6-
# load correctly. Firefox is not strictly required, but we need a web browser.
7-
- name: Install Ubuntu packages needed to run X server.
8-
apt:
9-
pkg={{ item }}
10-
state=latest
11-
update_cache=yes
12-
cache_valid_time=86400
13-
with_items:
14-
- dictionaries-common
15-
- xfce4
16-
- gnome-icon-theme-full
17-
- firefox
18-
sudo: yes
19-
20-
- name: Allow everyone to start X.
21-
lineinfile:
22-
dest=/etc/X11/Xwrapper.config
23-
create=yes
24-
state=present
25-
regexp="^allowed_users="
26-
line="allowed_users=anybody"
27-
sudo: yes
28-
29-
- name: Configure X to start at login.
30-
lineinfile:
31-
dest=/etc/skel/.bashrc
32-
create=yes
33-
state=present
34-
regexp="^[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx"
35-
line="[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx"
36-
sudo: yes
37-
38-
- name: Configure XFCE to start when startx is called.
39-
lineinfile:
40-
dest=/etc/skel/.xinitrc
41-
create=yes
42-
state=present
43-
regexp="^exec startxfce4"
44-
line="exec startxfce4"
45-
sudo: yes
46-
47-
# Replace existing XFCE4 wallpaper. Setting the wallpaper seems to require an
48-
# X-display, which seems overcomplicated.
49-
- name: Download and set wallpaper.
50-
get_url:
51-
url={{ WALLPAPER_URL }}
52-
force=yes
53-
dest=/usr/share/backgrounds/xfce/xfce-blue.jpg
54-
sudo: yes
55-
56-
- name: Set permissions of wallpaper.
57-
file:
58-
path=/usr/share/backgrounds/xfce/xfce-blue.jpg
59-
owner=root
60-
group=root
61-
mode=644
62-
sudo: yes
4+
- include: xfce.yml
5+
- include: wallpaper.yml

roles/xserver/tasks/wallpaper.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Replace existing XFCE4 wallpaper. Setting the wallpaper seems to require an
2+
# X-display, which seems overcomplicated.
3+
- name: Download and set wallpaper.
4+
get_url:
5+
url={{ WALLPAPER_URL }}
6+
force=yes
7+
dest=/usr/share/backgrounds/xfce/xfce-blue.jpg
8+
sudo: yes
9+
10+
- name: Set permissions of wallpaper.
11+
file:
12+
path=/usr/share/backgrounds/xfce/xfce-blue.jpg
13+
owner=root
14+
group=root
15+
mode=644
16+
sudo: yes
17+
18+
# Now we mark it, if it needs marking.
19+
- name: Define background location.
20+
set_fact:
21+
background_dir: /usr/share/backgrounds/xfce
22+
23+
- name: Determine whether or not the image is already marked.
24+
stat:
25+
path: "{{ background_dir }}/marked "
26+
register: marked
27+
28+
- name: Install ImageMagick (temporarily)
29+
apt:
30+
pkg=imagemagick
31+
state=latest
32+
update_cache=yes
33+
cache_valid_time=86400
34+
sudo: yes
35+
when: not marked.stat.exists
36+
37+
- name: Obtain watermark text.
38+
command: cat /vagrant/repository_version
39+
register: text
40+
when: not marked.stat.exists
41+
42+
# I am so sorry.
43+
#
44+
# First two converts create the stamp in two parts. The following composite
45+
# combines the stamp, and the mogrify effectively crops it. The final composite
46+
# applies the stamp to the wallpaper.
47+
#
48+
# At the end of this, a 'marked' placeholder file is added for idempotency.
49+
- name: Add version watermark.
50+
shell: |
51+
convert -size 450x150 xc:grey30 -pointsize 60 -gravity center -draw "fill grey70 text 0,0 '{{ text.stdout }}'" stamp_fore.png
52+
convert -size 450x150 xc:black -pointsize 60 -gravity center -draw "fill white text 2,2 '{{ text.stdout }}' text 0,0 '{{ text.stdout }}' fill white text -4,-4 '{{ text.stdout }}' fill black text -1,-1 '{{ text.stdout }}'" +matte stamp_mask.png
53+
composite -compose CopyOpacity stamp_mask.png stamp_fore.png stamp.png
54+
mogrify -trim +repage stamp.png
55+
composite -gravity south-east -geometry +0+10 stamp.png xfce-blue.jpg marked.jpg
56+
rm -rf stamp_fore.png stamp_mask.png stamp.png
57+
mv marked.jpg xfce-blue.jpg
58+
touch marked
59+
args:
60+
chdir: "{{ background_dir }}"
61+
creates: marked
62+
sudo: yes
63+
64+
- name: Remove ImageMagick
65+
apt:
66+
pkg=imagemagick
67+
state=absent
68+
sudo: yes

roles/xserver/tasks/xfce.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
# Important to install the packages in this order, otherwise icons will not
3+
# load correctly. Firefox is not strictly required, but we need a web browser.
4+
- name: Install Ubuntu packages needed to run X server.
5+
apt:
6+
pkg={{ item }}
7+
state=latest
8+
update_cache=yes
9+
cache_valid_time=86400
10+
with_items:
11+
- dictionaries-common
12+
- xfce4
13+
- gnome-icon-theme-full
14+
- firefox
15+
sudo: yes
16+
17+
- name: Allow everyone to start X.
18+
lineinfile:
19+
dest=/etc/X11/Xwrapper.config
20+
create=yes
21+
state=present
22+
regexp="^allowed_users="
23+
line="allowed_users=anybody"
24+
sudo: yes
25+
26+
- name: Configure X to start at login.
27+
lineinfile:
28+
dest=/etc/skel/.bashrc
29+
create=yes
30+
state=present
31+
regexp="^[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx"
32+
line="[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx"
33+
sudo: yes
34+
35+
- name: Configure XFCE to start when startx is called.
36+
lineinfile:
37+
dest=/etc/skel/.xinitrc
38+
create=yes
39+
state=present
40+
regexp="^exec startxfce4"
41+
line="exec startxfce4"
42+
sudo: yes
43+

0 commit comments

Comments
 (0)