1st Snap Need some assistance please

Hey all. Not sure if anyone can lend a hand. We are utilizing a bash script to install a player that we use to put media onto a digital screen. The script goes out and grabs the binaries and builds the player to run on Ubuntu. However, I am wanting to convert our entire inventory to Ubuntu Core, therefore, I need a snap package. Prior to signing the line and going that route, i need to build a snap of the player to ensure that it will work in a dev environment. But I don’t know jack about building snaps, or coding in general. Is anyone able to assist me in building this snap package? Below is the bash script for the player. I have only modified the URL for grabbing the binaries and the names of the players.


1. #!/bin/bash

2. set -o pipefail
3. set -o errexit
4. set -o nounset

5. if [[ $EUID -ne 0 ]]; then
6.     echo "This script must be run as root" 1>&2
7.     exit 1
8. fi

9. TARGET=/opt/jake/player
10. UPDATE_DIR=/opt/jake/update
11. REMOTE="https://fleet.jakepowered.com/download/latest/json"
12. ARCH=

13. case $(arch) in
14.     "x86_64")
15.         ARCH=x64
16.         ;;
17.     i?86)
18.         ARCH=ia32
19.         ;;
20.     *)
21.         echo "Unsupported architecture: $(arch)"
22.         exit 1
23. esac

24. function usage() {
25.     cat <<EOF
26.     Usage: $0 [options]

27.     Installs the latest version of the jake player under ${TARGET}.

28.     -u <username>   Both the jake player and the Watchdog processes will run
29.                     as <username>.
30.     [-n]            No Watchdog or autostart on login.
31.     [-i]            Install the version with interactive support.

32. EOF
33. }

34. USER=
35. NOWATCHDOG=
36. INTERACTIVE=

37. while getopts ":u:in" opt; do
38.     case $opt in
39.         u)
40.             USER=$OPTARG
41.             ;;
42.         i)
43.             INTERACTIVE=1
44.             ;;
45.         n)
46.             NOWATCHDOG=1
47.             ;;
48.         \?)
49.             echo "Invalid option: -$OPTARG" >&2
50.             exit 1
51.             ;;
52.         :)
53.             echo "Option -$OPTARG requires an argument." >&2
54.             exit 1
55.             ;;
56.     esac
57. done

58. if [ -z "$USER" ]
59. then
60.     usage
61.     exit 1
62. fi

63. if id -u "$USER" >/dev/null 2>&1; then
64.     mkdir -p $TARGET
65.     chown -R "$USER" "$TARGET"
66. else
67.     echo "Unknown user: $USER"
68.     exit 1
69. fi

70. apt-get update
71. apt-get install curl xdotool unclutter libudev1 python3 -y

72. if [ ! -z $INTERACTIVE ];
73. then
74.     ARCH="${ARCH}nosdk"
75. fi

76. VERSION_DETAILS=$(curl $REMOTE -# 2>/dev/null)
77. PLAYER_DOWNLOAD_URL=$(
78.   echo "$VERSION_DETAILS" \
79.     | grep "player/linux/$ARCH/url" \
80.     | awk -F'"' '{print $4}'
81. )
82. PLAYER_VERSION=$(
83.   echo "$VERSION_DETAILS" \
84.     | grep '"version"' \
85.     | awk -F'"' '{print $4}'
86. )
87. UPDATER_DOWNLOAD_URL=$(
88.   echo "$VERSION_DETAILS" \
89.     | grep "updater/linux/$ARCH/url" \
90.     | awk -F'"' '{print $4}'
91. )
92. UPDATER_VERSION=$(
93.   echo "$VERSION_DETAILS" \
94.     | grep '"updater-version"' \
95.     | awk -F'"' '{print $4}'
96. )

97. # Install the updater
98. mkdir -p $UPDATE_DIR
99. curl "${UPDATER_DOWNLOAD_URL}" -o "${UPDATE_DIR}/jake_update.py"
100. echo -e "\\e[32mjake updater v${UPDATER_VERSION} is installed under" \
101.         "${UPDATE_DIR}."
102. echo -en "\\033[0m"

103. # Install the player
104. if [[ -z "$PLAYER_DOWNLOAD_URL" || -z "$PLAYER_VERSION" ]]
105. then
106.     echo "Failed to get version details from jake server."
107.     exit 1
108. fi

109. mkdir -p "$TARGET"/"${PLAYER_VERSION}"

110. echo "Downloading the latest player version (v${PLAYER_VERSION}) from" \
111.      "$PLAYER_DOWNLOAD_URL"
112. curl "$PLAYER_DOWNLOAD_URL" -# | tar zxv -C "${TARGET}"/"${PLAYER_VERSION}"

113. if [ -e ${TARGET}/current ]
114. then
115.     rm ${TARGET}/current
116. fi

117. ln -s "${TARGET}"/"${PLAYER_VERSION}" "${TARGET}"/current

118. if [ ! -f /etc/ld.so.conf.d/jake.conf ];
119. then
120.     echo "${TARGET}/current/lib" > /etc/ld.so.conf.d/jake.conf
121.     ldconfig
122. fi

123. chown -R "$USER" "$TARGET"
124. chown -R "$USER" "$UPDATE_DIR"

125. UHOME=$( getent passwd "$USER" | cut -d: -f6 )
126. AUTOSTART_DIR="$UHOME/.config/autostart"
127. AUTOSTART_FILE="$AUTOSTART_DIR/jake.desktop"

128. if [ -z $NOWATCHDOG ];
129. then
130.     su -c "mkdir -p $AUTOSTART_DIR" "$USER"
131.     su -c "echo '' > $AUTOSTART_FILE" "$USER"
132.     su -c "echo '[Desktop Entry]' >> $AUTOSTART_FILE" "$USER"
133.     su -c "echo 'Type=Application' >> $AUTOSTART_FILE" "$USER"
134.     su -c "echo 'Exec=${TARGET}/current/jakePlayer' >> $AUTOSTART_FILE" \
135.       "$USER"
136.     su -c "echo 'Hidden=false' >> $AUTOSTART_FILE" "$USER"
137.     su -c "echo 'NoDisplay=false' >> $AUTOSTART_FILE" "$USER"
138.     su -c "echo 'X-GNOME-Autostart-enabled=true' >> $AUTOSTART_FILE" "$USER"
139.     su -c "echo 'Name=jakePlayer' >> $AUTOSTART_FILE" "$USER"
140.     su -c "echo 'Comment=jake player' >> $AUTOSTART_FILE" "$USER"
141.     echo -e "\\e[32mAutostart config written to \"$AUTOSTART_FILE\"."
142. fi



143. FLAGS_FILE="$UHOME/.jake/flags"

144. if [ ! -z $NOWATCHDOG ];
145. then
146.     su -c "mkdir -p $UHOME/.jake" "$USER"
147.     su -c "echo '--disable-watchdog' >> $FLAGS_FILE" "$USER"
148.     su -c "echo '--disable-alerts' >> $FLAGS_FILE" "$USER"
149.     FLAGS=$(tr ' ' '\n' < "$FLAGS_FILE" | sort -u | grep -v -e '^$')
150.     su -c "echo \"$FLAGS\" > $FLAGS_FILE" "$USER"
151. fi


152. echo -e "\\e[32mjake player v${PLAYER_VERSION} is installed under" \
153.         "${TARGET}/current."
154. echo -e "\\e[32mjake player will auto-configure once you complete the" \
155.         "registration."
156. echo -e "\\e[32mRun the \"${TARGET}/current/jakePlayer\" command on your" \
157.         "terminal as a normal user to start the player."
158. echo -en "\\033[0m"

We also have a docker image of the player. Here is the code with all of the dependencies from the docker file. My issue is I just don’t know where to even begin. Unfortunately, I don’t feel as if the tutorials I have read about building a snap package are helpful to my unique situation.


1. FROM ubuntu:20.04

2. ARG jake_PLAYER_VERSION
3. ENV DEBIAN_FRONTEND noninteractive
4. ENV HOME /home/jake

5. RUN mkdir -p /opt/jake/player /home/jake/.mplayer /home/jake/.config

6. RUN apt-get update && apt-get install -y \
7.     curl \
8.     chromium-browser libnss3 \
9.     matchbox-window-manager gconf2 libnss3 libgtk-3-0 libxdamage1 \
10.     libxi6 libxtst6 libpangocairo-1.0-0 libxss1 libxrandr2 libasound2 \
11.     libatk1.0-0 libx11-xcb1 matchbox-window-manager mplayer x11-utils  \
12.     libatomic1 libgbm1 libmfx1 libmfx-tools libva-drm2 libva-x11-2 vainfo \
13.     intel-media-va-driver-non-free intel-gpu-tools && \
14.     rm -rf /var/lib/apt/lists/*

15. RUN addgroup jake && \
16.     adduser --quiet --shell /bin/bash --home /home/jake --ingroup jake \
17.     --disabled-login --disabled-password --gecos "" jake && \
18.     usermod -aG video jake

19. RUN curl https://jake-player.s3.jake.com/production/jakePlayer-${jake_PLAYER_VERSION}-linux-x64.tar.gz \
20.     -o /tmp/player.tar.gz && \
21.     tar -xzf /tmp/player.tar.gz -C /opt/jake/player && \
22.     rm /tmp/player.tar.gz

23. RUN chown -R jake:jake /opt/jake /home/jake

24. COPY entrypoint.sh /opt/entrypoint.sh

25. RUN echo "lavdopts=threads=2" > $HOME/.mplayer/config

26. WORKDIR /home/jake

27. EXPOSE 9222

28. ENTRYPOINT ["/opt/entrypoint.sh"]

Please use three backticks ``` above and below things you paste, so they get recognized as code and the formatting stays intact, else it gets unreadable

Sorry about that. Is this better?

1 Like

Yup, a lot

1 Like