-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.sh
executable file
·102 lines (85 loc) · 3.35 KB
/
setup.sh
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
#!/bin/bash
echo "-=# SETUP #=-"
echo
# Define variables
username="calliope" # name for user
groups="dialout" # group(s) the user has to be added
needed_progs="lsblk md5sum cmp pip3"
if [ "${EUID}" -ne 0 ]; then
echo "Please run as root. Exiting."
exit 1
fi
# If command line argument is passed to script assume this is the username
# and overwrite variable ${username}
if [[ "${1}" != "" ]]; then
username=${1}
fi
# The CalliopEO software relies on some programs that have to be available on
# the system. Check and exit if one of the programs does not exist
# (see Github issue #91)
for prog in ${needed_progs}; do
command -v ${prog} >/dev/null 2>&1 || {
echo >&2 "Error: ${prog} required but it's not installed. Exiting."
exit 1
}
done
# Determine UUIDs
uuid_mini=$(lsblk -o MODEL,UUID | grep -i "MSD[ -_]Volume" | awk '{print $2}')
uuid_flash=$(lsblk -o MODEL,UUID | grep -i "MSD[ -_]Flash" | awk '{print $2}')
# If the variables ${uuid_mini} and ${uuid_flash} are empty, some error
# occured (Calliope Mini not atached to Rasperry Pi). In this exit with error
# message
if [[ "${uuid_mini}" == "" || "${uuid_flash}" == "" ]]; then
echo "Error detecting Calliope Mini. Exiting"
exit 1
else
echo "Calliope detected."
echo " UUID Mini: ${uuid_mini}"
echo " UUID Flash: ${uuid_flash}"
fi
# -----------------------------------------------------------------------------
# Below this point the setup script perfoms changes to the system
# If calliope user doesn't exist, create it. If the user already exists,
# exit setup.sh (see Github issue #88)
if ! id -u ${username} > /dev/null 2>&1; then
echo "Creating user ${username}."
useradd -m ${username}
else
echo "Error: User ${username} already exists. Exiting."
exit 1
fi
# Add user to groups in ${groups}. If user is already in the groups the
# command has no effect
echo "Assign user ${username} to group(s): ${groups}"
usermod -a -G ${groups} ${username}
# Get user id and group id for later use
user_id=$(id -u ${username})
group_id=$(id -g ${username})
# Ask to provide/change password for user
read -p "Add/change password for ${username}? [yN]" ans
if [[ ${ans} =~ [Yy]$ ]]; then
passwd ${username}
fi
# Copy all the files from the respository to the home directory of
# user ${usernanme}
echo "Copying files to /home/${username}/calliopEO"
mkdir -p /home/${username}/calliopEO/
cp -r . /home/${username}/calliopEO/.
# Create mount points
echo "Creating local mount points in /home/${username}/mnt/"
mkdir -p /home/${username}/mnt/mini
#mkdir -p /home/${username}/mnt/flash
# Adjust the uid and gui for all files in user directory
chown -R ${user_id}:${group_id} /home/${username}
# Create mount point in /etc/fstab that can be mounted by user calliope
echo "Adding mount point definition to /etc/fstab"
echo "# Mount point for Calliope Mini" >> /etc/fstab
echo "/dev/disk/by-uuid/${uuid_mini} /home/${username}/mnt/mini vfat noauto,users 0 0" >> /etc/fstab
#echo "/dev/disk/by-uuid/${uuid_flash} /home/${username}/mnt/flash vfat noauto,users 0 0" >> /etc/fstab
# Install all Python modules from folder /modules
# First, copy the folder /modules to the home directory of ${username}.
# Then, install locally as user ${username}
echo "Installing Python modules"
su - ${username} -c 'cd && for m in ~/calliopEO/modules/*.whl; do python3 -m pip install --user ${m}; done'
echo "Finished!"
exit 0